File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xs:element Vs xs:attribute

 
kri shan
Ranch Hand
Posts: 1453
  • 0
  • 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: 20196
26
MySQL Database
  • 0
  • 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: 1453
  • 0
  • 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: 20196
26
MySQL Database
  • 0
  • 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: 1453
  • 0
  • 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: 20196
26
MySQL Database
  • 0
  • 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: 1453
  • 0
  • 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: 20196
26
MySQL Database
  • 0
  • 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: 1453
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic