Handle two XML files with one schema file

invidicult

I have a short question to my XSD Problem. I have created an test.xsd file how should handle 2 XML types. One for my database and one for an third party application.

It works great whether I use the database XML files, but in the third Party software the XML tag is on another position. Let me explain:

Database XML summary:

<tempData> 123456 </tempData>
<DataSet> 505 </DataSet>

third party software xml summary:

<DataSet> 505 </DataSet>
<tempData> 123456 </tempData>

XSD summary:

    <xs:complexType>
    <xs:sequence>
        <xs:element name="Data" minOccurs="0" maxOccurs="unbounded">
            <xs:complexType>
                <xs:sequence>               
                    <xs:element ref="tempData" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element ref="DataSet" minOccurs="0" maxOccurs="unbounded" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:sequence>
</xs:complexType>
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="tempData" />
            <xs:element ref="DataSet" />
          </xs:choice>
        </xs:complexType>
      </xs:element>

When I would like to validate these two different XML files with my XSD file for the database XML file it works and for the third party XML file with the inverted tags it will not validate.

How can I handle these two different arrangements?

Steve Padmore

below is a solution that will allow both 'DataSet' and 'tempData' to be present in the 'Data' element, either both at the same time (in any order), one or the other alone, or neither of them (empty 'Data' element).

If you wish to force either one to be present, change the minOccurs to '1'. You cannot have more than one of each of these elements within the 'Data' element when using 'xs:all' - either minimum 0 or 1.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Data">
    <xs:complexType>
      <xs:all>
        <xs:element name="tempData" minOccurs="0" />
        <xs:element name="DataSet" minOccurs="0" />
      </xs:all>
    </xs:complexType>
  </xs:element>
</xs:schema>

Try it with:

<Data>
  <DataSet> 505 </DataSet>
  <tempData> 123456 </tempData>
</Data>

<Data>
  <tempData> 123456 </tempData>
  <DataSet> 505 </DataSet>
</Data>

<Data>
  <DataSet> 505 </DataSet>
</Data>

<Data>
  <tempData> 123456 </tempData>
</Data>

<Data>
</Data>

And your XML will be valid

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related