File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes xs:element  Vs   xs:attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xs:element  Vs   xs:attribute" Watch "xs:element  Vs   xs:attribute" New topic
Author

xs:element Vs xs:attribute

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1383
Looks xs:element and xs:attribute are same. When to use xs:element or xs:attribute ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

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: 1383
<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: 18993
    
    8

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: 1383
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: 18993
    
    8

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: 1383
<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: 18993
    
    8

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: 1383
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
 
subject: xs:element Vs xs:attribute