Attributes are simple name/value pairs associated with an element.
<Order id="0000000001">
Attribute value must be enclosed in single or double quotes
The same rules apply to naming attributes as apply to naming elements: Names are case sensitive, can't start with xml, and so on.
XML parser will "normalize" the data in an attribute before it passes it on to the application.
Use attribute or element??
- Some times you have to make a decision to use child node or attribute.
- For readability purpose, elements are reader friendly
- Elements are more flexible because they can have attributes of their own
- Sometimes attribute can be more intuitive, see example below
is better than<note type="Information">This is a note.</note>
<note>
<type>Information</type>
This is a note.
</note>
or
<note><Information>This is a note.</Information></note>