Groups | Blog | Home
all groups > dotnet xml > august 2004 >

dotnet xml : Problem defining an XSD to validate for overlapping ranges


Derek Harmon
8/29/2004 11:29:13 AM
[quoted text, click to view]
: :

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

Jim Di Griz
8/29/2004 12:41:00 PM
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>

AddThis Social Bookmark Button