8

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

Shax
  • 4,207
  • 10
  • 46
  • 62

2 Answers2

12

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/

user1619480
  • 533
  • 8
  • 18
3

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

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • @Shax the restrictions does not afefct the class, just the validation, see here how to validate: http://stackoverflow.com/questions/6451519/how-to-use-xsd2code-generated-c-classes/6451593#6451593 – Felice Pollano Jun 23 '11 at 13:27
  • 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.? – Shax Jun 23 '11 at 13:38
  • 3
    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? – MacX Dec 13 '12 at 13:53