Home > Articles > Web Services > XML

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

1.3 Attributes


Elements can be annotated with attributes. Attributes can be used to encode actual data or to provide metadata about an element—that is, provide extra information about the content of the element on which they appear. The attributes for a given element are serialized inside the start tag for that element. Attributes appear as name/value pairs separated by an equal sign (=). Attribute names have the same construction rules as element names. Attribute values are textual in nature and must appear either in single quotes or double quotes. An element may have any number of attributes, but they must all have different names.


Data attributes

<Person name='Martin' age='33' />

A person represented using attributes rather than child elements

Metadata attributes

<age base='16' units='years' >20</age>
<age base="10" units="years" >32</age>

Some elements with metadata attributes

  • + Share This
  • 🔖 Save To Your Account