XML Schema never-never occurence of declared elements / attributes

Discussion in 'XML' started by Soren Kuula, Nov 28, 2005.

  1. Soren Kuula

    Soren Kuula Guest


    1) If I have a definition + declaration like
    <complexType name="fattype">
    <element name="bar" minOccurs="0" maxOccurs="342"/>
    <attribute name="shanyang"/>

    <element name="foo" type="fattype"></element>

    and I want to make a derived-by-restriction subtype where the bar
    element never appears, is there ANY other way to go than:

    <element name="thinfoo">
    <restriction base="fattype">
    <element name="bar" maxOccurs="0"/>
    <attribute name="shanyang" use="prohibited"/>

    OK - my question really is: Looking at the declaration of thinfoo, I
    have to make a set of element names that may occur as child elements of
    thinfoo in any valid instance document. They don't HAVE to appear, there
    just must a the possibility that they do. Now there is an element in the
    content model of thinfoo that is declared, but never appears in an
    instance, and thus should not be included in my set.

    Can any of you guys / girls tell my whether this approach is safe:

    Case: E is derived by restriction, or implicitly by extension from anyType:
    - I traverse the whole content model of the E declaration recursively.
    If I encounter an element with a minOccurs="0" (actual value) attribute,
    then I ignore the element and its subelements. Otherwise, if the element
    is an element declaration and it has a name, I add the name to my set,
    but don't recurse. If it is an element declaration with a ref attribute,
    I add it to my set, too.

    Case: E is derived by extension (explicitly):
    - I traverse the declaration like above. Then, I run the same algorithm
    on the type that the base attribute refers to, and add the result of
    that to my set.

    -- will this get me the right set? Or are there other ways a declared
    element may actually never appear in an instance?

    And: Are there, likewise, any other way a declared attribute may never
    appear, than a use="prohibited" attribute on its declaration?

    Can anyone see any reason that I should bother to look at the base
    declaration in the case of a derivation by restriction?

    Hope there's a Schema expert out there who can help me -- and that some
    sort of Medal of Honar may be awarded to those who have read the entire
    spec with no nervous breakdowns.

    Soren Kuula, Nov 28, 2005
    1. Advertisements

  2. Re: XML Schema never-never occurence of declared elements /attributes

    Soren Kuula writes:

    Given this (corrected) type definition

    <complexType name="fattype">
    <element name="bar" minOccurs="0" maxOccurs="342"/>
    <attribute name="shanyang"/>

    The non-misleading restriction you want is

    <element name="thinfoo">
    <restriction base="fattype">
    <attribute name="shanyang" use="prohibited"/>

    This is of course an element useful only as an illustration, as it
    must always be empty, with no attributes.

    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Dec 1, 2005
    1. Advertisements

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.