schema, attributes, interdependent restrictions

Discussion in 'XML' started by Marc Hebert, May 24, 2008.

  1. Marc Hebert

    Marc Hebert Guest

    I'm trying to figure out if something is possible to specify and
    constrain using a schema. I'll explain using an example.

    sample xml:
    <person name="John" age="32"/>
    <person name="Julie" age="25"/>

    In my schema, I'd love to be able to place different restrictions on
    the attribute 'age' based on the value of 'name'... so in this
    example, I might want to enforce that any entry where name="John"
    includes an age attribute that falls between 30-39, and that Julie's
    age value is 20-29.

    What I tried to do, and is invalid, is define a JohnPerson and
    JuliePerson element type, and then specify that I expected a list
    (all) of elements having an element name="person" and
    type="JohnPerson", "JuliePerson", etc... by the parser rejected that
    with "Multiple elements with name 'person', with different types,
    appear in the model group."

    Any ideas?

    Many thanks,
    Marc
    Marc Hebert, May 24, 2008
    #1
    1. Advertising

  2. * Marc Hebert wrote in comp.text.xml:
    >I'm trying to figure out if something is possible to specify and
    >constrain using a schema. I'll explain using an example.
    >
    >sample xml:
    ><person name="John" age="32"/>
    ><person name="Julie" age="25"/>
    >
    >In my schema, I'd love to be able to place different restrictions on
    >the attribute 'age' based on the value of 'name'... so in this
    >example, I might want to enforce that any entry where name="John"
    >includes an age attribute that falls between 30-39, and that Julie's
    >age value is 20-29.


    This is not possible with XML Schema 1.0. You could check out NVDL (with
    multiple XML Schema schemas), RELAX NG, and Schematron (possibly XML
    Schema with embedded Schematron), none of which will work in simple XML
    Schema 1.0 implementations of course.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
    Bjoern Hoehrmann, May 24, 2008
    #2
    1. Advertising

  3. Marc Hebert

    Marc Hebert Guest

    On May 23, 7:43 pm, Bjoern Hoehrmann <> wrote:
    > * Marc Hebert wrote in comp.text.xml:
    >
    > >I'm trying to figure out if something is possible to specify and
    > >constrain using a schema. I'll explain using an example.

    >
    > >sample xml:
    > ><person name="John" age="32"/>
    > ><person name="Julie" age="25"/>

    >
    > >In my schema, I'd love to be able to place different restrictions on
    > >the attribute 'age' based on the value of 'name'... so in this
    > >example, I might want to enforce that any entry where name="John"
    > >includes an age attribute that falls between 30-39, and that Julie's
    > >age value is 20-29.

    >
    > This is not possible with XML Schema 1.0. You could check out NVDL (with
    > multiple XML Schema schemas), RELAX NG, and Schematron (possibly XML
    > Schema with embedded Schematron), none of which will work in simple XML
    > Schema 1.0 implementations of course.
    > --
    > Björn Höhrmann · mailto: ·http://bjoern.hoehrmann.de
    > Weinh. Str. 22 · Telefon: +49(0)621/4309674 ·http://www.bjoernsworld.de
    > 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 ·http://www.websitedev.de/


    Thanks very much for that info, that saves me a few hours of trying to
    do something impossible.

    Marc
    Marc Hebert, May 24, 2008
    #3
  4. Marc Hebert

    hugo Guest

    test
    "Marc Hebert" <> wrote in message
    news:...
    >
    > I'm trying to figure out if something is possible to specify and
    > constrain using a schema. I'll explain using an example.
    >
    > sample xml:
    > <person name="John" age="32"/>
    > <person name="Julie" age="25"/>
    >
    > In my schema, I'd love to be able to place different restrictions on
    > the attribute 'age' based on the value of 'name'... so in this
    > example, I might want to enforce that any entry where name="John"
    > includes an age attribute that falls between 30-39, and that Julie's
    > age value is 20-29.
    >
    > What I tried to do, and is invalid, is define a JohnPerson and
    > JuliePerson element type, and then specify that I expected a list
    > (all) of elements having an element name="person" and
    > type="JohnPerson", "JuliePerson", etc... by the parser rejected that
    > with "Multiple elements with name 'person', with different types,
    > appear in the model group."
    >
    > Any ideas?
    >
    > Many thanks,
    > Marc
    hugo, May 24, 2008
    #4
    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. Jean-Marie Condom
    Replies:
    2
    Views:
    395
    Jean-Marie Condom
    Nov 26, 2004
  2. Moth
    Replies:
    2
    Views:
    420
  3. Replies:
    3
    Views:
    488
    Mike Rawlins
    Dec 10, 2003
  4. poematrix
    Replies:
    2
    Views:
    410
    Martin Honnen
    Sep 7, 2004
  5. Replies:
    4
    Views:
    440
Loading...

Share This Page