Jump to content

Xsd Schema With Optional Elements


nidabp

Recommended Posts

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></DOCUMENT></DOCUMENTS> I am trying to generate a XSD where I don't want to specify about the elements other than T1 and T4.I need only to verify if T1 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 <T5></T5> and I don't want to update the XSD. And also the elements can occur in any order. The elements T1 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:choice>.. Any help is apprieciated.

Link to comment
Share on other sites

  • 11 months later...
:glare: May be it's usefull for you....
<?xml version="1.0" encoding="utf-8"?><DOCUMENTS><DOCUMENT>  <T4>TEST4t</T4>  <T1>TEST1w</T1>  <T23>TEST2</T23>  <T33>TEST3</T33>  <T33>TEST3</T33>  <T33>TEST3</T33>  <T33>TEST3</T33>  <T33>TEST3</T33>  <T34>TEST3222</T34>  </DOCUMENT></DOCUMENTS>

<?xml version="1.0" encoding="utf-8"?><xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">  <xs:element name="DOCUMENTS">    <xs:complexType>      <xs:sequence>        <xs:element name="DOCUMENT">          <xs:complexType>            <xs:sequence>              <xs:choice minOccurs="1" maxOccurs="1">                <xs:element name="T1"/>                <xs:element name="T4"/>              </xs:choice>              <xs:any minOccurs="0" maxOccurs='unbounded' processContents='skip'/>            </xs:sequence>          </xs:complexType>        </xs:element>      </xs:sequence>    </xs:complexType>  </xs:element></xs:schema>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...