Attribute versus Attribute Value

An attribute is a property of an element. It has a name and a value and is normally a part of the element's start-tag. (It can also be defaulted in from the DTD.) For example, consider this element:

 <Headline page="10">Crowd Hears Beth Giggle</Headline> 

The headline element has a page attribute with the value 10 . The attribute includes both the name and the value. The attribute value is simply the string 10 . Either single or double quotes may surround the attribute valuethe type of quote used is not significant. This element is exactly the same as the previous one:

 <Headline page='10'>Crowd Hears Beth Giggle</Headline> 

If an element has multiple attributes, their order is not important. These two elements are equivalent:

 <Headline id="A3" page="10">Crowd Hears Beth Giggle</Headline> <Headline page="10" id="A3">Crowd Hears Beth Giggle</Headline> 

Parsers do not tell you which attribute came first. If order matters, you need to use child elements instead of attributes:

 <Headline>   <id>A3</id> <page>10</page>   Crowd Hears Beth Giggle </Headline> 

It's not exactly a terminology confusion, but a few technologies (notably the W3C XML Schema Language) have recently dug themselves into deep holes by attempting to treat attributes and child elements as variations of the same thing. They are not. Order is only one of the differences between child elements and attributes. Other important differences include type, normalization, and the ability or inability to express substructure .



Effective XML. 50 Specific Ways to Improve Your XML
Effective XML: 50 Specific Ways to Improve Your XML
ISBN: 0321150406
EAN: 2147483647
Year: 2002
Pages: 144

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net