我有多个描述对象的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 ../常见/ 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
进行某种配置更改吗?或者是由其他地方引起的错误?
感谢。
答案 0 :(得分:0)
我写了一个循环文件并打印文件名的小脚本,所以我可以使用:
xsd.exe / c file1.xsd file2.xsd file3.xsd
这应该有效:)
PS。我知道我加入了晚会;)