Using XSD.exe to generate c# classes from multiple XSD schemas

26,274

Solution 1

Pass just the "main" xsd as a parameter, ensure the other is in the same location of the main, and it should work.

Solution 2

Referencing the main XSD did not work for me.

I had to reference the dependant XSD files as per this link

http://bembengarifin.wordpress.com/2009/07/14/generate-net-class-from-xsd-with-references-to-other-xsd-using-xsd-exe/

Share:
26,274
Shax
Author by

Shax

Updated on June 27, 2020

Comments

  • Shax
    Shax almost 4 years

    I have 2 XSD files.

    One XSD file lets say ABC.xsd contains the elements which are part of XML. The other XSD file lets say XYZ.xsd contains the definations of those elements.

    Now in ABC.XSD(which holds the elements) schema tag along with other namespaces we have mentioned the schemalocation as well

    <xs:schema schemaLocation="XYZ.xsd">
    

    When I am executing xsd.exe to genereate my C# classes. It is generating classes but missing some definations from XYZ.xsd.

    I am executing

    xsd.exe "ABC.xsd" "XYZ.xsd" /c
    

    Any help would be appreicate

    EDIT 1: @Felice, in my XYZ.xsd I have defination like this

    <xs:simpleType name="contactNumberType">
            <xs:annotation>
                <xs:documentation>Contact phone or fax number with national or international format.  Only numbers are allowed</xs:documentation>
            </xs:annotation>
            <xs:restriction base="xs:string">
                <xs:pattern value="\+?\p{N}{6,24}"/>
            </xs:restriction>
        </xs:simpleType>
    

    See the pattern defined here, it is not appearing in the C# class. Any help. Sorry I am new to this . Thanks your answer worked

  • Felice Pollano
    Felice Pollano almost 13 years
    @Shax the restrictions does not afefct the class, just the validation, see here how to validate: stackoverflow.com/questions/6451519/…
  • Shax
    Shax almost 13 years
    I am sorry I am lost. What I thought was by executing the XSD.exe it will generated the c# classes and will put all the restrictions etc as part of the c# code.?
  • MacX
    MacX over 11 years
    And what is about it, when you got multiple starting xsd-files referencing each other? Is it possible to generate only one class, although it will be needed in others?