aspose 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
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: 12912
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.
jQuery in Action, 2nd edition
subject: XML: Element or Attribute