The Datatypes and How They Work
Three of the basic datatypes that are supported by XML Document
Type Definitions (DTDs) and XML Schemas are ID, IDREF, and IDREFS. The ID and IDREF datatypes work according to two
rules:
Every attribute of datatype
IDmust be unique.Every value of datatype
IDREFmust match a value of an attribute of datatypeIDsomewhere in the document.
An attribute with a datatype of IDREFS contains one or more space-separated
values, each of which must match a value of an ID elsewhere in the document. The IDREFS datatype is a list of IDREF values, just as its name
implies.
Here is a simple DTD fragment that uses the ID and IDREF datatypes:
<?xml version="1.0"?> <!-- parts-list1.xml --> <!DOCTYPE parts-list [ <!ELEMENT parts-list (component+, part+)> <!ELEMENT component (name, partref+)> <!ATTLIST component component-id ID #REQUIRED> <!ELEMENT name (#PCDATA)> <!ELEMENT partref EMPTY> <!ATTLIST partref refid IDREF #REQUIRED> <!ELEMENT part (name)> <!ATTLIST part part-id ID #REQUIRED> ]> <parts-list> ... </parts-list>
Here is the XML Schema definition of the same document type:
<?xml version="1.0" encoding="UTF-8"?>
<!-- parts-list.xsd --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="parts-list"> <xs:complexType> <xs:sequence> <xs:element ref="component" minOccurs="1" maxOccurs="unbounded"/> <xs:element ref="part" minOccurs="1" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="component"> <xs:complexType> ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access