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[]”。存在显式转换(您是否缺少演员表?)

我从错误中看到的是类的生成出现了问题。我认为几个类被声明了两次,这就是为什么将“1”放在名称的末尾。

我可以使用某种配置更改xsd.exe吗?还是其他地方引起的错误?

谢谢。

4

1 回答 1

0

我写了一个小脚本来循环文件并打印它们的文件名,所以我可以使用:

xsd.exe /c 文件1.xsd 文件2.xsd 文件3.xsd

那应该工作:)

PS。我知道我迟到了 ;)

于 2017-02-28T15:25:18.220 回答