473,382 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

problem Validating sequnece of Tag values using schema

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
Jul 20 '05 #1
1 1391
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>

--------------------------------------------------------------------------------------------------------------------------------
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: davisjoseph | last post by:
Hi All, I'm using Xerces C++ 2.50 DOM version for Validating a valid XML againt the Schema(XSD) available; But it always shows an error in XSD I suppose; This is the error I'm getting using...
3
by: Uwe Kuhne | last post by:
I receive a XML file from a customer and want to use a schema for validating the XML file. What I don't know how to do is, that I want to continue processing this XML - file no matter if there is...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
3
by: Shailendra Batham | last post by:
hi guys I need your suggestions / opinion for doing this the right way. I have a XML and a Schema for the same What I want is when its validated against the schema, it should give custom...
5
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the...
2
by: tomek.romanowski | last post by:
Hi ! I have problem with validating of the document with multiple namespaces. The odd thing is, that my data work O'K when I test it under XMLSpy but it doesn't work with my C# code. My first...
4
by: Sergey Poberezovskiy | last post by:
Hi, As part of my schema I need to ensure that at least one of two fields have values. I defined my schema as follows: .... <xs:choice> <xs:element ref="el1"/> <xs:element ref="el2"/>...
12
by: steve_marjoribanks | last post by:
I'm fairly new to XML and schemas and I'm trying to work out why a schema I've been given keeps throwing up validation errors in XMLSpy. The section of code with the problem is: ...
1
by: Chris Lieb | last post by:
I have an XML Schema file that I know is correct becuase I currently use it in a VB6 program to validate XML documents. Also, if I load an XML file into VS2005 that is not valid against this...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.