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 XML:  Element or Attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML:  Element or Attribute" Watch "XML:  Element or Attribute" New topic
Author

XML: Element or Attribute

Jeff Hinsman
Greenhorn

Joined: Sep 10, 2009
Posts: 3
I am new to XML. Just curious. Generically speaking, which is better, an attribute or element. I guess you can't have repeating attributes.


Thanks,

New Java Developer ;)
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
As I am sure you expected, the answer is "it depends" - there are some generalizations:

As you mentioned, repeating items belong in elements.

Elements are required for text that has to be in CDATA sections.

Attributes are ideal for "metadata" qualifying the element content.

Bill


Java Resources at www.wbrogden.com
Jeff Hinsman
Greenhorn

Joined: Sep 10, 2009
Posts: 3
Thanks! I think the key there is metadata. I am taking over some schema's someone else created an almost everything is an attribute. Seemed "ugly" to me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML: Element or Attribute
 
Similar Threads
General XML related question...
New to XML Question
Question on XML Schema restriction
connection timeout.
Significance of this tag