• 1 reply
  • Latest Post - ‏2011-10-24T09:34:49Z by mukulg
1 Post

Pinned topic XML Schema creation with optional elements

‏2011-10-19T12:20:27Z |
I need to generate a XSD from XML DataFile. My Data looks like

I am trying to generate a XSD where I don't want to specify about the elements other than T2 and T4.I need only to verify if T2 and T4 exists and the schema validation should fail if any of them does not exist. Because the data file may change tomorrow and I can add a new element <T6></T6> and I don't want to update the XSD. And also the elements can occur in any order. The elements T2 and T4 should occur only once and they are mandatory.

I am trying to use <xs:any> attribute, but I am not able to use it along with <xs:all>..

Any help is apprieciated
Updated on 2011-10-24T09:34:49Z at 2011-10-24T09:34:49Z by mukulg
  • mukulg
    22 Posts

    Re: XML Schema creation with optional elements

    With XSD 1.0, you can't specify wild-card within <all>. With XSD 1.1 this is allowed. Here's a 1.1 schema which may solve your use case,
    <xs:schema xmlns:xs=
    "">   <xs:element name=
    "DOCUMENTS"> <xs:complexType> <xs:sequence> <xs:element name=
    "DOCUMENT"> <xs:complexType> <xs:all> <xs:element name=
    "T2"/> <xs:element name=
    "T4"/> <xs:any processContents=
    "skip" maxOccurs=
    "unbounded"/> </xs:all> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>