This property is a Microsoft extension to the W3C DOM.
Object Attr CDATASection
CharacterData Comment Document DocumentFragment
DocumentType Entity EntityReference Node
Notation ProcessingInstruction Text
Object.definition
The definition property is a read-only property that returns the definition of the
node in the DTD or schema.
The value depends on the nodeType property. The four relevant
node types are as follows (all the other types return null):
- NODE_ENTITY_REFERENCE
returns the node for the entity referenced; i.e. the entity element that was
defined for a given entity reference. So, with an entity reference of &pa;, this
property would return the node in the DOCTYPE that defines the corresponding
entity: <!ENTITY pa "personal assistant">.
- NODE_ENTITY
for unparsed entities this property returns the
Notation definition from the DOCTYPE. For parsed entities
it returns null
- NODE_ATTRIBUTE
returns the XML-Data Schema AttributeType for a given
Attr node. Returns null if a DTD is used, or no
schema is present.
- NODE_ELEMENT
returns the XML-Data Schema ElementType for a given
Element node. Returns null if a DTD is used,
or no schema is present.
To demonstrate how the definition property might be used, we will load the
'albums.xml' file, which has the following structure:
XML:
<Albums>
<Album ref="CD142" category="Folk">
<title>Boil The Breakfast Early</title>
<artist>The Chieftains</artist>
</Album>
</Albums>
Each 'Album' element has a 'ref' attribute which is defined in a Schema as follows:
<AttributeType name='ref' dt:type='string' required='yes' />
Our code first creates a NamedNodeMap of all the
attributes of the first 'Album' element. It then uses the definition property to
create a Node object of the Schema definition of the first of these
attributes (ref). Finally, the attributes of that node are copied to a NamedNodeMap,
and the code iterates through the collection displaying the
nodeName of each.
Code (JavaScript):
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("albums.xml");
atts = xml_doc.documentElement.firstChild.attributes;
attr = atts[0];
def = attr.definition;
atts = def.attributes;
n_atts = atts.length;
for (i = 0; i < n_atts; i++)
document.write(atts[i].nodeName + "<br>");
Output:
name
dt:type
required
|