ID, IDREF, and IDREFS Attributes




Download 2,96 Mb.
Pdf ko'rish
bet79/131
Sana14.05.2024
Hajmi2,96 Mb.
#232039
1   ...   75   76   77   78   79   80   81   82   ...   131
Bog'liq
Ceponkus, Hoodbhoy - Applied XML - Toolkit for Programmers

ID, IDREF, and IDREFS Attributes
ID, IDREF, and IDREFS are similar. ID attributes are unique identifiers of an element. 
Once you declare an element to have an attribute of type ID, its ID value must be unique 
for every element of that type in your XML document. Think of them as primary keys from 
database theory. The good thing about IDs is they ensure that each such element can be 
uniquely identified (if you have elements with the same ID attribute value in your XML, 
the parser lets you know). The bad thing if you’re writing the XML document yourself is 
that you’ve got to make sure you create a unique ID for each element (though that’s not 
too tough to do as a programmer, so long as you have a well defined 
nomenclature/scheme).
It is important that the value of an ID attribute has a particular format. It must start with 
either a letter, an underscore (_), or a colon (:). An ID cannot be a pure numerical value. 
This is good at many levels, yet frustrating at others.
Here’s how to declare assign an ID type attribute to a part element:
ID
default
>


- 81 -
A valid part could look like this:
more part information
An IDREF is a pointer to the any of the unique IDs previously stated in the document. If 
the above part element has been included in the document (with its unique 
code_number), then it is possible to refer to it only on the basis of its ID value. Here’s the 
attribute declaration:
IDREF
default
>
A valid part_to_order element would be:
more part_to_order information
The IDREFS type is similar except that it allows multiple references to IDs. An attribute 
declaration of a parts_to_order element could look like this:
IDREFS
default
>
The corresponding valid element could look like this:
 more parts_to_order 
information 

Download 2,96 Mb.
1   ...   75   76   77   78   79   80   81   82   ...   131




Download 2,96 Mb.
Pdf ko'rish