【问题标题】:xsd.exe class generator issues with multiple xsd files多个 xsd 文件的 xsd.exe 类生成器问题
【发布时间】:2012-10-28 16:58:20
【问题描述】:

我有多个描述一个对象的 XSD 文件。我想从这些对象生成类,这样我就可以解析 XML 并创建该对象。我使用了 Visual Studio 提供的xsd.exe,如下所示:

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[]”隐式转换为 '寄售类型 1[]'。存在显式转换(您是否缺少 演员?)

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

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

谢谢。

【问题讨论】:

    标签: xsd.exe


    【解决方案1】:

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

    xsd.exe /c file1.xsd file2.xsd file3.xsd

    应该可以的:)

    PS。我知道我迟到了 ;)

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      相关资源
      最近更新 更多