XML DOM » Node » definition

Compability: Internet Explorer

Syntax:
node.definition

This property returns the definition of the node in the DTD or schema.

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.

Examples

Code:
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
Explanation:

To demonstrate how the definition property might be used, we will load the 'albums.xml' file, which has the following structure:

<Albums>
   <Album ref="CD142" category="Folk">
      <title>Boil The Breakfast Early</title>
      <artist>The Chieftains</artist>
   </Album>
</Albums>

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.

Language(s): JavaScript