Schema maxInclusive puzzle

Discussion in 'XML' started by Don Adams, Feb 20, 2004.

  1. Don Adams

    Don Adams Guest

    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>?

    --
    Don Adams
     
    Don Adams, Feb 20, 2004
    #1
    1. Advertising

  2. Don Adams

    Derek Harmon Guest

    "Don Adams" <> wrote in message news:c15up3$11ieth$...
    > 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
     
    Derek Harmon, Feb 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,672
    Markus
    Nov 23, 2005
  2. Klaus Johannes Rusch

    Re: Convert DB2 schema to XML Schema

    Klaus Johannes Rusch, Aug 6, 2003, in forum: XML
    Replies:
    0
    Views:
    573
    Klaus Johannes Rusch
    Aug 6, 2003
  3. Brett Selleck

    Schema Metadata not a Metadata Schema

    Brett Selleck, Sep 4, 2003, in forum: XML
    Replies:
    1
    Views:
    436
    Andy Dingley
    Sep 4, 2003
  4. Fred Smith
    Replies:
    1
    Views:
    1,002
    Martin Honnen
    Feb 5, 2004
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,333
    Stanimir Stamenkov
    Apr 25, 2005
Loading...

Share This Page