This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xs:element Vs xs:attribute

 
kri shan
Ranch Hand
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks xs:element and xs:attribute are same. When to use xs:element or xs:attribute ?
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<order_details>
<order_id>123A</order_id>
<price>243</price>
</order_details>

order_id and price is attribute (or) element in XSD ?
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After reading some articles, my understanding:
element is for simple/complex types. atrribute is only for simple types.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic