3

I have multiple XSD files that describe an object. I want to generate the class from these objects so I can parse an XML that and create that object. I used xsd.exe that Visual Studio provides as follows:

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

The efreight-CommonReportingSchema-1.0.xsd file :

<!-- ===== 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>

The cs file is generated successfully but when I try to parse the object, several errors occur like the following:

error CS0266: Cannot implicitly convert type 'ShipmentStageType[]' to 'ShipmentStageType1[]'. An explicit conversion exists (are you missing a cast?)

error CS0266: Cannot implicitly convert type 'TransportHandlingUnitType[]' to 'TransportHandlingUnitType1[]'. An explicit conversion exists (are you missing a cast?)

error CS0266: Cannot implicitly convert type 'ConsignmentType[]' to 'ConsignmentType1[]'. An explicit conversion exists (are you missing a cast?)

What I see from the errors is that something went wrong in the generation of the class. I think that several classes are declared twice and that's why the '1' is put in the end of the name.

Is there some kind of configuration change that I can use for xsd.exe? Or is the error caused by somewhere else?

Thanks.

Jason
  • 2,503
  • 3
  • 38
  • 46
marios
  • 65
  • 1
  • 2
  • 6

1 Answers1

0

I wrote a small script that loops the files and prints their filenames, so i can use:

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

That should work :)

PS. I know i'm joining late to the party ;)

NicoJuicy
  • 3,435
  • 4
  • 40
  • 66