File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML:  Element or Attribute" Watch "XML:  Element or Attribute" New topic

XML: Element or Attribute

Jeff Hinsman

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.


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

Joined: Mar 22, 2000
Posts: 13037
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.

Jeff Hinsman

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:
subject: XML: Element or Attribute
It's not a secret anymore!