problem Validating sequnece of Tag values using schema

M

mangesh

Hi,
In the following XML, I need to validate the values provided in Order
tag using schema.

<?xml version="1.0" encoding="UTF-8"?>
<Control xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Columns>
<SequenceNumber>
<DisplayName>Sequence #</DisplayName> <!-- Column Name to be
displayed.-->
<Display>Y</Display> <!-- N -> Hide and Y -> Show -->
<Order>3</Order>
</SequenceNumber>
<DocType>
<DisplayName>Doc. Type</DisplayName>
<Display>Y</Display>
<Order>2</Order>
</DocType>
<DistrNumber>
<DisplayName>Distr. #</DisplayName>
<Display>Y</Display>
<Order>1</Order>
</DistrNumber>
</Columns>
</Control>

Following are the cases to be validated:

Order: 1,2,3 - Valid
Order: 2,1,3 - Valid
Order: 3,2,1 -Valid
Order: 1,1,1 - Invalid
Order: 1,3,4 - Invalid
Order: 4,5,6 - Invalid


Thanks in advance,
Mangesh
 
M

mangesh

Here is the solution---

Control.XML

<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
<WidgetItem>
<Order>1</Order>
</WidgetItem>
<WidgetItem>
<Order>2</Order>
</WidgetItem>
<WidgetItem>
<Order>3</Order>
</WidgetItem>
</Transaction>

--------------------------------------------------------------------------------------

Control.XSD

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Transaction">
<xs:complexType>
<xs:sequence>
<!-- Permit between 1 and 3 -->
<xs:choice minOccurs="0">
<xs:element ref="WidgetItem" minOccurs="0" maxOccurs="3" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<!-- Enforce that if any widgets are present then they are uniquely
numbered -->
<xs:key name="WidgetKey">
<xs:selector xpath="WidgetItem" />
<xs:field xpath="Order" />
</xs:key>
</xs:element>

<!-- A type representing a single widget -->
<xs:complexType name="Widget">
<xs:sequence>
<xs:element name="Order">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
<!-- The main elements for a Transaction-->
<xs:element name="WidgetItem" type="Widget" />
</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

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top