468,527 Members | 2,091 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,527 developers. It's quick & easy.

Could anyone explain this schema structure?

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.

Nov 25 '05 #1
3 1448


we*********@gmail.com wrote:

"<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).

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
http://JavaScript.FAQTs.com/
Nov 25 '05 #2
Martin Honnen wrote:
we*********@gmail.com wrote:

"<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).

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>


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 :o).

Nov 25 '05 #3
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: ht@inf.ed.ac.uk
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
Nov 28 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by ruthless | last post: by
2 posts views Thread by Victor Engmark | last post: by
14 posts views Thread by Ina Schmitz | last post: by
3 posts views Thread by Kiran | last post: by
reply views Thread by Derek | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.