467,894 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Problem defining an XSD to validate for overlapping ranges

Hi

I have a problem to create an XSD that prevents overlapping ranges.

Sample XML:

<root>
<element LowerLimit="1" UpperLimit="50000">
.....
</element>
<element LowerLimit="50001" UpperLimit="250000">
.....
</element>
<element LowerLimit="250001" UpperLimit="500000">
.....
</element>
......
</root>

<element> is always of the same structure
<root> has minOccurs="1" and maxOccurs="unbounded"

range1 1 to 50000
range2 50001 to 250000
range3 250001 to 500000

Is it possible to create a schema that throws a validation error when ranges
overlap like in the following sample:

<root>
<element LowerLimit="1" UpperLimit="50000">
.....
</element>
<element LowerLimit="25000" UpperLimit="40000">
.....
</element>
<element LowerLimit="40001" UpperLimit="500000">
.....
</element>
......
</root>
Nov 12 '05 #1
  • viewed: 1454
Share:
1 Reply
"Jim Di Griz" <s_*****@hotmail.com> wrote in message news:OC**************@TK2MSFTNGP11.phx.gbl...
Is it possible to create a schema that throws a validation error when ranges
overlap like in the following sample:

<root>
<element LowerLimit="1" UpperLimit="50000">
.....
</element>
<element LowerLimit="25000" UpperLimit="40000">
.....

: :

No. XML Schema is very limited in what sort of validations it can perform
that are external to an element. It's very good at validating everything about
an element: it's data type, required and optional particles, it's content model,
the regexp patterns of it's text. Once the validation of an element or attribute
comes to the question of basing the "is valid?" question on content _elsewhere_
in the XML document, XML Schema really starts to breakdown.

XML Schema has some capabilities when it comes to ensuring referential
integrity between elements, that means you can require some attribute (as
if it were a foreign key) of one element to match a "primary key" existing
elsewhere in the instance document. The logic, however, required to perform
range validations are outside of it's scope.

You might consider an alternative schema definition language, like RELAX NG
or Schematron. Otherwise, I'd perform a validation of this nature programmatically
in C#/VB.NET with DOM code and XmlDocument, or it's also probably possible
in XSLT (not ideal, IMO, but possible).
Derek Harmon
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Max M | last post: by
3 posts views Thread by Phil Sandler | last post: by
13 posts views Thread by Reuben Chew | last post: by
4 posts views Thread by Simon Elliott | last post: by
2 posts views Thread by Chesne | last post: by
4 posts views Thread by Wysiwyg | last post: by
12 posts views Thread by Adam Hartshorne | last post: by
4 posts views Thread by Mohsen | last post: by
7 posts views Thread by Breal | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.