problem Validating sequnece of Tag values using schema

Discussion in 'XML' started by mangesh, Jan 30, 2004.

  1. mangesh

    mangesh Guest

    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
     
    mangesh, Jan 30, 2004
    #1
    1. Advertising

  2. mangesh

    mangesh Guest

    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>

    --------------------------------------------------------------------------------------------------------------------------------
     
    mangesh, Feb 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,670
    Markus
    Nov 23, 2005
  2. shruds
    Replies:
    1
    Views:
    957
    John C. Bollinger
    Jan 27, 2006
  3. Jasmin Wason
    Replies:
    0
    Views:
    507
    Jasmin Wason
    Aug 1, 2003
  4. Yona
    Replies:
    0
    Views:
    565
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,330
    Stanimir Stamenkov
    Apr 25, 2005
Loading...

Share This Page