The xml:id Attribute

The xml:id attribute is a method for guaranteeing proper ID processing.

Example

<message xml:id="i-35867"
>This is a message</message>

Description

Under XML 1.0, an ID is a unique identifier to aid in processing. You can annotate an element uniquely with an attribute of type ID, as in id="i-35867" (IDs can’t start with a number), which often assumes an associated DTD containing the attribute-list declaration <!ATTLIST message id ID #REQUIRED>. Likewise, XML Schema provides a mechanism for identifying markup as having type ID with the type="xs:ID" attribute, as with <xs:attribute name="id" type="xs:ID">. The problem is that non-validating yet conformant XML processors are not required to refer to or process an external subset DTD (one that exists outside of the XML document), and a correct schema may not be available, so processing IDs can be troublesome. Implementation of the xml:id attribute is an attempt to guarantee that ID processing will be consistent and reliable, whether the XML processor being used is validating or not. The xml:id mechanism is currently a W3C candidate recommendation, and it’s a development worth tracking. The upcoming specs for XPath 2.0—and hence XQuery and XSLT 2.0—also support xml:id.

See also

The xml:id spec: http://www.w3.org/TR/xml-id/

Get XML Pocket Reference, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.