Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

From the author of

ID and IDREF Attributes

The ID and IDREF types are complementary. The XML ID mechanism is intended to give document authors a way to uniquely identify elements within a document. The IDREF attribute type indicates that the attribute can contain only a value that matches an ID value within the same document. Here are a few points to remember about ID and IDREF attributes:

  • ID values must be valid XML names—that is, start with a letter or underscore (_), and contain only letters, numbers, and certain punctuation.

  • No two elements (even of different element types) can have the same value in an ID attribute. For instance, having two elements <person id="ID20"/> and <company id="ID20"/> in a single document would make that document invalid.

  • Every IDREF attribute must match the value of an ID attribute somewhere in the document. IDREFs are like one-way links to elements, and it's illegal to have a document containing broken links.

  • + Share This
  • 🔖 Save To Your Account