Schema maxInclusive puzzle

D

Don Adams

I don't think what I want to do with maxInclusive is possible, but
I thought I'd ask others what they thought. As an example,
here is some very simple XML:

<birthday_cake>
<max_pieces>8</max_pieces>
<serving name="Joe">
<pieces>2</pieces>
</serving>
<serving name="Jane">
<pieces>1</pieces>
</serving>
</birthday_cake>

Is it possible to write a Schema rule to ensure that the maxInclusive
restriction
for <pieces> is equal to the value of <max_pieces>? In other words,
to ensure that no serving contains more pieces than the max_pieces for
the birthday_cake.

Now for the real stretch, is it possible to write a Schema rule to ensure
that the total of all <pieces> under <birthday_cake> is less-than or
equal-to the value of <max_pieces> for <birthday_cake>?
 
D

Derek Harmon

Don Adams said:
I don't think what I want to do with maxInclusive is possible, but
I thought I'd ask others what they thought.

I agree that it is not possible in XML Schema.

XML Schema defines the structure of an XML instance
document, but it is incapable of validating the content of
structural members against the content of _other_
structural members (you can use enumerations and
regular expression patterns to validate the content of
the structural member currently being validated; that's
about it.)

: :
<birthday_cake>
<max_pieces>8</max_pieces>
<serving name="Joe">
<pieces>2</pieces>
</serving>
<serving name="Jane">
<pieces>1</pieces>
</serving>
</birthday_cake>

Is it possible to write a Schema rule to ensure that the maxInclusive
restriction for <pieces> is equal to the value of <max_pieces>?

What you would look for in XML Schema is some manner of
referencing the other members of the document within the
maxInclusive attribute, like allowing XPath expressions.
You won't find this.

One workaround that is sometimes used is to supplement the
validation process of XML Schema with something that does
have intrinsically strong support for XPath expressions: XSLT.

After using XML Schema to validate the structural qualities of
your instance document, its possible to run an XSLT stylesheet
against the instance document that will do inter-element content
validation.

This stylesheet can be as simple as something that returns a
literal text answer to the question of validity: true or false?

It could also be sophisticated enough to return "0 OK" for valid
content, or an error message describing what is invalid, "107
More pieces of cake served (11) than exist pieces of birthday
cake (8)."


Derek Harmon
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top