| Author |
xs:element Vs xs:attribute
|
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
|
|
|
Looks xs:element and xs:attribute are same. When to use xs:element or xs:attribute ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
kri shan wrote:Looks xs:element and xs:attribute are same.
Surely not. Can you explain what made you think that?
|
 |
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
|
|
<order_details>
<order_id>123A</order_id>
<price>243</price>
</order_details>
order_id and price defined in XSD as xs:element or xs:attribute ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
|
That's not a schema, it's an XML document. If you have a question about a schema which is supposed to describe that document, you should show us the schema you are asking about.
|
 |
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
|
|
It's typo, not XSD. It's XML.
<order_details>
<order_id>123A</order_id>
<price>243</price>
</order_details>
XSD:
-----
<xs:complexType name="OrderDetails">
<xs:element name="order_id" type="xs:string">
<xs:element name="price" type="xs:float">
</xs:complexType>
(or)
<xs:complexType name="OrderDetails">
<xs:attribute name="order_id" type="xs:string">
<xs:attribute name="price" type="xs:float">
</xs:complexType>
Which is correct ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
What do you mean by "correct"?
Only one of those schemas describes the document you posted, it's true. But it should be obvious which one it is if you know the difference between an element and an attribute.
Perhaps that was your question in the first place? If so, you're asking in a very roundabout way.
|
 |
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
|
|
<order_details>
<order_id>123A</order_id>
<price>243</price>
</order_details>
order_id and price is attribute (or) element in XSD ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
What you posted is not an XSD (schema). It's just an ordinary XML document.
Here's a link to an XML tutorial which might explain some useful concepts.
|
 |
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
|
|
After reading some articles, my understanding:
element is for simple/complex types. atrribute is only for simple types.
|
 |
 |
|
|
subject: xs:element Vs xs:attribute
|
|
|