Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Could anyone explain this schema structure?

Reply
Thread Tools

Could anyone explain this schema structure?

 
 
wesley.hall@gmail.com
Guest
Posts: n/a
 
      11-25-2005
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.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-25-2005


http://www.velocityreviews.com/forums/(E-Mail Removed) 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/
 
Reply With Quote
 
 
 
 
Wesley Hall
Guest
Posts: n/a
 
      11-25-2005
Martin Honnen wrote:

> (E-Mail Removed) 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 ).

 
Reply With Quote
 
Henry S. Thompson
Guest
Posts: n/a
 
      11-28-2005
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: (E-Mail Removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
anyone could explain this to me? robertchen117@gmail.com Perl Misc 9 03-18-2007 09:01 PM
Could anyone explain this Yahoo! source code? =?Utf-8?B?QW5kcmV3?= ASP .Net 1 05-04-2006 02:17 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Could anyone explain the code for me? C++fan C++ 14 01-05-2004 04:16 AM
String, String literal ? Could anyone explain to me ? herrcho C Programming 7 09-26-2003 04:54 PM



Advertisments