XML Schema question

Discussion in 'XML' started by Gregg Williams, Aug 26, 2003.

  1. Hi--I am having a problem designing a schema to fit my XML data, and I'm
    hoping that someone can help. Essentially, I have a schema in mind and two
    target vocabularies for it, where one vocabulary is a subset of the other. I
    will describe one part of the schema to give you an idea of what my problem
    is.

    The "big" schema calls for 0 or more selector elements, each containing a
    (required) name attribute and simple character data, as follows:

    <selector name="wakka">foo</selector>

    The "small" schema calls for 1 or more selector elements with a name of
    "key", followed by 0 or more selector elements with any value for the name
    attribute:

    <selector name="key">estimate</selector>

    <selector name="key">summary</selector>

    <selector name="custom1">low-priority</selector>

    As you can see, the small schema is a subset of the large schema.

    My problem is that I can't find a way to define a parent element than can
    describe the sequence of selector elements required by the small schema.
    I've looked at redefinition, substitution groups, and other tricks for
    making a schema open-ended. The problem is that they all require me to write
    something like the following within a complex type definition:

    <xsd:sequence>

    <xsd:element maxOccurs="unbounded" minOccurs="1" name="selector"
    type="selectorKeyType"/>

    <xsd:element maxOccurs="unbounded" minOccurs="0" name="selector"
    type="selectorType"/>

    </xsd:sequence>

    ....where selectorKeyType and selectorType are defined as follows:

    <xsd:complexType name="selectorType">

    <xsd:simpleContent>

    <xsd:extension base="xsd:token">

    <xsd:attribute name="name" type="xsd:NCName"/>

    </xsd:extension>

    </xsd:simpleContent>

    </xsd:complexType>

    <!-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ -->

    <xsd:complexType name="selectorKeyType">

    <xsd:simpleContent>

    <xsd:restriction base="selectorType">

    <xsd:attribute fixed="key" name="name" type="xsd:NCName"/>

    </xsd:restriction>

    </xsd:simpleContent>

    </xsd:complexType>

    The Xerxes parser reminds me that multiple elements with the same name must
    have the same type:

    [Message:E cos-element-consistent: Error for type '<ignore --gw>'. Multiple
    elements with name 'selector', with different types, appear in the model
    group. SystemID:file:/C:/xml/misc/schema-experiments/exper3/exper.xsd,
    Line:35, Column:34, Offset:-1]

    Of course, I could write my own code that would validate a given XML file
    has been valid under the little schema, but the differences between the big
    and little schemas are considerable. I could also describe the constrained
    selector element using a slightly different name--cselector, for
    example--but that would more or less negate the original design: namely,
    that custom elements are distinguished from "official" elements only by the
    value of the name attribute.

    Is there a way to do what I want to do? Or is the inability of the XML
    Schema to handle this situation an indication that what I am trying to do is
    a Bad Thing? Thanks.

    --gw
     
    Gregg Williams, Aug 26, 2003
    #1
    1. Advertising

  2. Gregg Williams

    Bob Foster Guest

    "Gregg Williams" <> wrote in message
    news:...
    > Hi--I am having a problem designing a schema to fit my XML data, and I'm
    > hoping that someone can help. Essentially, I have a schema in mind and two
    > target vocabularies for it, where one vocabulary is a subset of the other.

    I
    > will describe one part of the schema to give you an idea of what my

    problem
    > is.
    >
    > The "big" schema calls for 0 or more selector elements, each containing a
    > (required) name attribute and simple character data, as follows:
    >
    > <selector name="wakka">foo</selector>
    >
    > The "small" schema calls for 1 or more selector elements with a name of
    > "key", followed by 0 or more selector elements with any value for the name
    > attribute:
    >
    > <selector name="key">estimate</selector>
    >
    > <selector name="key">summary</selector>
    >
    > <selector name="custom1">low-priority</selector>


    Can't do this. Elements with the same name in a sequence must have the same
    type.

    And (reading ahead a bit) you already know this! The Xerces parser told you
    so.

    Redesign your data model (which looks like a good idea in this case) or use
    a more expressive schema language, like RELAX NG.

    Bob Foster

    > As you can see, the small schema is a subset of the large schema.
    >
    > My problem is that I can't find a way to define a parent element than can
    > describe the sequence of selector elements required by the small schema.
    > I've looked at redefinition, substitution groups, and other tricks for
    > making a schema open-ended. The problem is that they all require me to

    write
    > something like the following within a complex type definition:
    >
    > <xsd:sequence>
    >
    > <xsd:element maxOccurs="unbounded" minOccurs="1" name="selector"
    > type="selectorKeyType"/>
    >
    > <xsd:element maxOccurs="unbounded" minOccurs="0" name="selector"
    > type="selectorType"/>
    >
    > </xsd:sequence>
    >
    > ...where selectorKeyType and selectorType are defined as follows:
    >
    > <xsd:complexType name="selectorType">
    >
    > <xsd:simpleContent>
    >
    > <xsd:extension base="xsd:token">
    >
    > <xsd:attribute name="name" type="xsd:NCName"/>
    >
    > </xsd:extension>
    >
    > </xsd:simpleContent>
    >
    > </xsd:complexType>
    >
    > <!-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ -->
    >
    > <xsd:complexType name="selectorKeyType">
    >
    > <xsd:simpleContent>
    >
    > <xsd:restriction base="selectorType">
    >
    > <xsd:attribute fixed="key" name="name" type="xsd:NCName"/>
    >
    > </xsd:restriction>
    >
    > </xsd:simpleContent>
    >
    > </xsd:complexType>
    >
    > The Xerxes parser reminds me that multiple elements with the same name

    must
    > have the same type:
    >
    > [Message:E cos-element-consistent: Error for type '<ignore --gw>'.

    Multiple
    > elements with name 'selector', with different types, appear in the model
    > group. SystemID:file:/C:/xml/misc/schema-experiments/exper3/exper.xsd,
    > Line:35, Column:34, Offset:-1]
    >
    > Of course, I could write my own code that would validate a given XML file
    > has been valid under the little schema, but the differences between the

    big
    > and little schemas are considerable. I could also describe the constrained
    > selector element using a slightly different name--cselector, for
    > example--but that would more or less negate the original design: namely,
    > that custom elements are distinguished from "official" elements only by

    the
    > value of the name attribute.
    >
    > Is there a way to do what I want to do? Or is the inability of the XML
    > Schema to handle this situation an indication that what I am trying to do

    is
    > a Bad Thing? Thanks.
    >
    > --gw
    >
    >
     
    Bob Foster, Aug 27, 2003
    #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,663
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    997
    Martin Honnen
    Feb 5, 2004
  3. Hari Om
    Replies:
    1
    Views:
    482
    Martin SChukrazy
    Mar 2, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,328
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    3
    Views:
    3,172
Loading...

Share This Page