How to prevent duplicate child element definitions in the XSD

J

johkar

My XSD is rather large, On occaison we will duplicate a child element
in the XSD which causes problems when imported into the vendor
application we are using. I know how to control the number of element
occurances in the XML using the XSD, but is there a way to catch upon
save (validation) in XMLSpy when someone is trying to add a duplicate
child element within the XSD?

Sample XML and XSD follow. The XML elements aren't always named the
same under each TABLE, this is just a representation.

<?xml version="1.0" encoding="UTF-8"?>
<MYROOT>
<REQUEST>
<TABLE1>
<ELEMENT1>string</ELEMENT1>
<ELEMENT2>string</ELEMENT2>
</TABLE1>
<TABLE2>
<ELEMENT1>string</ELEMENT1>
<ELEMENT2>string</ELEMENT2>
</TABLE2>
</REQUEST>
</MYROOT>


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="MYROOT">
<xs:complexType>
<xs:sequence>
<xs:element name="REQUEST">
<xs:complexType>
<xs:sequence>
<xs:element ref="TABLE1" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="TABLE2" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="TABLE1">
<xs:complexType>
<xs:sequence>
<xs:element name="ELEMENT1" type="xs:string" maxOccurs="1"/>
<xs:element name="ELEMENT2" type="xs:string" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="TABLE2">
<xs:complexType>
<xs:sequence>
<xs:element name="ELEMENT1" type="xs:string" maxOccurs="1"/>
<xs:element name="ELEMENT2" type="xs:string" maxOccurs="1"/>
<!--
need to catch this upon save (validation) in XMLSpy -->
<xs:element name="ELEMENT2" type="xs:string" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top