DTD Attribute Types - IDREF

The attribute type of IDREF is used for referring to an ID value of another element in the document.

Syntax:

Copy to Clipboard
<!ATTLIST element_name
attribute_name IDREF default_value>

Example:

Copy to Clipboard
<!ATTLIST employee
employee_id ID #REQUIRED
manager_id IDREF #IMPLIED>

Valid XML - The following XML document would be valid, as it conforms to the above DTD:

Copy to Clipboard
<employees>
  <employee employee_id="e10001" manager_id="e10002">
    <first_name>Homer</first_name>
    <last_name>Flinstone</last_name>
  </employee>
  <employee employee_id="e10002">
    <first_name>Fred</first_name>
    <last_name>Burns</last_name>
  </employee>
</employees>

Invalid XML - The following XML document would be invalid. This is because the "manager_id" attribute of the second element contains a value that isn't the same as a value of another element that contains an attribute with a type of ID:

Copy to Clipboard
<employees>
  <employee employee_id="e10001" manager_id="e10002>
    <first_name>Homer</first_name>
    <last_name>Flinstone</last_name>
  </employee>
  <employee employee_id="e10002" manager_id="e10003>
    <first_name>Fred</first_name>
    <last_name>Burns</last_name>
  </employee>
</employees>

Enjoy this page?

Sponsored Link: Design CODE-FREE Websites

Check a Domain:

ZappyHost Logo
Webydo Banner Ad