Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
1 reply Latest Post - ‏2011-10-24T09:34:49Z by mukulg
nidabp
nidabp
1 Post
ACCEPTED ANSWER

Pinned topic XML Schema creation with optional elements

‏2011-10-19T12:20:27Z |
Hi,
I need to generate a XSD from XML DataFile. My Data looks like
<DOCUMENTS>
<DOCUMENT>
<T1>TEST1</T1>
<T2>TEST2</T2>
<T3>TEST3</T3>
<T4>TEST4</T4>
<T5>TEST5</T5>
</DOCUMENT>
</DOCUMENTS>

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
    mukulg
    22 Posts
    ACCEPTED ANSWER

    Re: XML Schema creation with optional elements

    ‏2011-10-24T09:34:49Z  in response to nidabp
    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=
    "http://www.w3.org/2001/XMLSchema">   <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>
    


    Thanks.