3

オブジェクトを記述する複数の XSD ファイルがあります。XML を解析してそのオブジェクトを作成できるように、これらのオブジェクトからクラスを生成したいと考えています。xsd.exeVisual Studio が次のように提供するものを使用しました。

xsd /c efreight-CommonReportingSchema-1.0.xsd ../common/efreight-CommonReportingSchemaExtensions-1.0.xsd ../common/UBL-CommonAggregateComponents-2.1.xsd ../common/UBL-CommonBasicComponents-2.1.xsd ../common /UBL-UnqualifiedDataTypes-2.1.xsd

efreight-CommonReportingSchema-1.0.xsdファイル:

<!-- ===== Imports ===== -->
<xsd:import namespace="urn:eu:specification:efreight:schema:xsd:CommonReportingSchemaExtensions-1.0" schemaLocation="../common/efreight-CommonReportingSchemaExtensions-1.0.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" schemaLocation="../common/UBL-CommonAggregateComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" schemaLocation="../common/UBL-CommonBasicComponents-2.1.xsd"/>
<xsd:import namespace="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2" schemaLocation="../common/UBL-UnqualifiedDataTypes-2.1.xsd"/>

<!-- ===== Common Reporting Schema Definition ===== -->
<xsd:element name="CommonReportingSchema" type="CommonReportingSchemaType">
</xsd:element>

<xsd:complexType name="CommonReportingSchemaType">
    <xsd:sequence>          
        <xsd:element ref="cbc:UBLVersionID" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="cbc:CustomizationID" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="cbc:ProfileID" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="cbc:ID" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="cbc:VersionID" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="cbc:TransportExecutionPlanReferenceID" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="crs:SubmissionDate" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="crs:SubmissionTime" minOccurs="0" maxOccurs="1"/>
        <xsd:element ref="crs:ReportingParty" minOccurs="1" maxOccurs="1"/>
        <xsd:element ref="crs:Consignment" minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element ref="crs:TransportMeans" minOccurs="0" maxOccurs="1"/>         
        <xsd:element ref="cac:DocumentReference" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

cs ファイルは正常に生成されますが、オブジェクトを解析しようとすると、次のようないくつかのエラーが発生します。

エラー CS0266: 型 'ShipmentStageType[]' を 'ShipmentStageType1[]' に暗黙的に変換することはできません。明示的な変換が存在します (キャストがありませんか?)

エラー CS0266: 型 'TransportHandlingUnitType[]' を 'TransportHandlingUnitType1[]' に暗黙的に変換することはできません。明示的な変換が存在します (キャストがありませんか?)

エラー CS0266: 型 'ConsignmentType[]' を 'ConsignmentType1[]' に暗黙的に変換することはできません。明示的な変換が存在します (キャストがありませんか?)

エラーからわかるのは、クラスの生成で何か問題が発生したことです。いくつかのクラスが 2 回宣言されていると思います。そのため、名前の最後に「1」が付けられています。

に使用できる何らかの構成変更はありますxsd.exeか? または、エラーは別の場所で発生していますか?

ありがとう。

4

1 に答える 1