The DocumentType object provides an interface to any entities and notations declared
for a document. A DocumentType object is returned by the document's
doctype property.
In the example that follows the 'staff.xml' file is used which contains a couple of
entities defined in the DOCTYPE declaration:
XML:
<!DOCTYPE staff SYSTEM "staff.dtd" [
<!ENTITY snrex "senior executive">
<!ENTITY pa "personal assistant">
]>
<staff>
<employee ssn="123456" pay="3">
<name>John Sullivan</name>
<position>&snrex;</position>
</employee>
<employee ssn="987654" pay="2">
<name>Mary Lopez</name>
<position>&pa;</position>
</employee>
</staff>
Note:
The code above represents the raw XML; when viewed in a browser both of the entities
'&snrex;' and '&pa;' will be expanded to the values defined for them in the DOCTYPE
declaration (i.e. 'senior executive' and 'personal assistant' respectively).
The code then gets a DocumentType object for this document, and produces a
NamedNodeMap of all its entities. It then iterates through the
list displaying the name and text of each.
Code (VBScript):
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("staff.xml")
Set DocType = objXMLDoc.doctype
Set EntList = DocType.entities
For Each Ent In EntList
document.write(Ent.nodeName)
document.write(": " & Ent.text & "<br>")
Next
Output:
snrex: senior executive
pa: personal assistant
A DocumentType is also a Node object, and so inherits
various properties and methods from it. For details of the values returned by the
nodeName,
nodeType and nodeValue
properties for an DocumentType, see the Node object.
denotes a Microsoft extension to the W3C DOM.
PROPERTIES
attributes Property
This is a read-only property that returns an
NamedNodeMap for nodes that can have
attributes.
Syntax: Node.attributes
baseName Property
This is a read-only property that returns the base name for a node.
Syntax: Node.baseName
childNodes Property
This is a read-only property containing a node list of all children for those elements that
can have them.
Syntax: Node.childNodes
dataType Property
This is a read-only property that specifies the data type for the node.
Syntax: Node.dataType
definition Property
This property returns the definition of the node in the DTD or schema.
Syntax: Node.definition
entities Property
This property contains a NamedNodeMap of all entities
(both internal and external) declared in the Document Type Definition. Duplicates are
ignored.
Syntax: DocumentType.entities
firstChild Property
This is a read-only property that returns the first child node of a node. If there is none,
it returns null.
Syntax: Node.firstChild
lastChild Property
This is a read-only property that returns the last child node of a node. If there is none,
it returns null.
Syntax: Node.lastChild