Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > problem Validating sequnece of Tag values using schema

Reply
Thread Tools

problem Validating sequnece of Tag values using schema

 
 
mangesh
Guest
Posts: n/a
 
      01-30-2004
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 xmlnssi="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
 
Reply With Quote
 
 
 
 
mangesh
Guest
Posts: n/a
 
      02-03-2004
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 xmlnss="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>

--------------------------------------------------------------------------------------------------------------------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
How to programatically assign a validating schema using Xerces? Duncan Smith XML 1 12-15-2003 04:05 PM
Validating xml with xsd schema using xerces Yona XML 0 10-29-2003 01:04 PM
Validating with in-memory Xml Schema using Xerces Jasmin Wason XML 0 08-01-2003 03:15 PM



Advertisments