Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

Attributes

Elements are the most fundamental component of an XML document; all XML documents have at least one element, the root element. However, there is also another fundamental mechanism for XML documents, which allows associating name/value pairs with elements: attributes.

Attributes should already be familiar to you from HTML:

<IMG SRC="logo.gif" BORDER="0">

The IMG tag makes use of many attributes, including the SRC attribute, which is used to associate the location of the image, and the BORDER attribute, which specifies the width of the image border.

Attributes Supplement Elements

Attributes are best utilized to store data that might not be important to the document structurally, but increase the informational value of an element. For example, in a document describing photographic equipment, we might have a camera element. For the camera element, it might make sense to have an attribute called format with values such as APS or 35mm. That's an attribute that relates to the element; it makes sense. However, you probably wouldn't want to have an attribute called phone, unless it's a very unusual camera.

  • + Share This
  • 🔖 Save To Your Account