Reputation: 11
I am trying to write a XSD for the following XML snippet.
<loop id="1000" name="loop 1000" />
<loop id="1000" name="loop 1000" />
<loop id="2000" name="loop 2000" />
<loop id="2000" name="loop 2000" />
<loop id="2000" name="loop 2000" />
I wrote the following XSD
<xs:element name="loop" maxOccurs="3">
<xs:simpleType>
<xs:attribute use="required" fixed="1000" type="xs:string" name="id" />
</xs:simpleType>
</xs:element>
<xs:element name="loop" maxOccurs="3">
<xs:simpleType>
<xs:attribute use="required" fixed="2000" type="xs:string" name="id" />
</xs:simpleType>
</xs:element>
But this seems to be failing in XML validation.
The XML is not in my control. How do I handle this?
EDIT:
I wrote a xml parser+generator and changed the received XML to something like
<_1000>...</_1000>
<_1000>...</_1000>
<_2000>...</_2000>
<_2000>...</_2000>
<_2000>...</_2000>
Now I can write the XSD easily for this.
Upvotes: 1
Views: 3189
Reputation: 11
<xs:element name="loop" minOccurs="3" maxOccurs="3">
<xs:simpleType>
<xs:attribute use="required" fixed="1000" type="xs:string" name="id" />
<xs:attribute use="required" fixed="loop 1000" type="xs:string" name="name" />
</xs:simpleType>
</xs:element>
<xs:element name="loop" minOccurs="3" maxOccurs="3">
<xs:simpleType>
<xs:attribute use="required" fixed="2000" type="xs:string" name="id" />
<xs:attribute use="required" fixed="loop 2000" type="xs:string" name="name" />
</xs:simpleType>
</xs:element>
Upvotes: 1