Could anyone explain this schema structure?

Discussion in 'XML' started by wesley.hall, Nov 25, 2005.

  1. wesley.hall

    wesley.hall Guest

    Hello,

    I have worked with XML fairly extensively but have generally used DTDs
    to describe the structure of my documents. Recently I decided to try to
    pick up XML Schemas and have been following the w3cschools tutorial. I
    was getting by fine until I came across one specific example...

    They say that the element..

    "<shoesize country="france">35</shoesize>"

    Can be described using a schema like...

    "<xs:element name="shoesize">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:integer">
    <xs:attribute name="country" type="xs:string" />
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>"

    What I dont understand here is the location of the xs:attribute element
    in the schema. It seems to suggest that the attribute is a child of the
    character data value (xs:extension). This feels uncomfortable to me,
    surely the xs:attribute element would be better placed as a subelement
    of xs:complex type making the shoesize element consist of a
    'complexType' with 1 piece of simple content (an xs:integer) and one
    attribute named country.

    Is there a logical reason why the xs:attribute is a subelement of
    xs:extension and if so, would somebody be kind enough to explain it to
    me so that I can reconsile it in my head and move on?

    Thank you very much for your time.
     
    wesley.hall, Nov 25, 2005
    #1
    1. Advertisements


  2. What you see is an anonymous type definition of a complex type for an
    element that has a simple content but an attribute.
    If you want to have an element have attributes then in terms of the W3C
    XML schema language that element always has a complex type, even if its
    content is empty or a simple content. So in terms of the type system the
    simple base type xs:integer is extended to define a complex type with
    simple element contents and one attribute.
    You might not like it but that is the way it is supposed to happen in
    that schema language:
    <http://www.w3.org/TR/xmlschema-1/#Type_Derivation>
     
    Martin Honnen, Nov 25, 2005
    #2
    1. Advertisements

  3. wesley.hall

    Wesley Hall Guest

    Ahhh I understand. This is inheiritance in the same vein as in OOP. I
    am creating a subtype of xs:Integer that I extend to include a country
    attribute. I get it.

    I have to say though, you are right, I dont like it. XML has a
    heirarchy at its core with subelements (You might argue that XML
    subelements are an example of composition rather than inheiritance and
    you would probably be right, but I have found that most problems can be
    solved with either inheiritance or composition with composition being
    cleaner in about 85% of cases). I have no idea why a new form of
    element inheiritance was needed and even if it was, the example above
    would be much cleaner if I were creating an exension of 'complexType'
    rather than creating an extension of Integer. An element with an
    integer in character data and a atttribute 'country' is a 'kind of'
    complexType not a 'kind of' integer. Poor design in my opinion, but
    perhaps I should probably wait until I have more than a few hours
    experience with a technology before I critize it ;o).

    Anyway. Thank you for your help :eek:).
     
    Wesley Hall, Nov 25, 2005
    #3
  4. I think you're being overly sensitive to the shape of the XML
    representation of the XML Schema component structures -- if you look
    at the shape of the complex type definition itself [1], and the
    relationships between a base type definition and type definitions
    derived from it by extension or restriction, you'll see something
    which looks more like what you're expecting.

    ht

    [1] http://www.w3.org/TR/xmlschema-1/
    --
    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, Nov 28, 2005
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.