class DOM_Document : public DOM_Node

Class to refer to XML Document nodes in the DOM

Inheritance:


Public

Constructors and assignment operators
DOM_Document ()
The default constructor for DOM_Document creates a null DOM_Document object that refers to no document
DOM_Document (const DOM_Document &other)
Copy constructor
DOM_Document& operator = (const DOM_Document &other)
Assignment operator
DOM_Document& operator = (const DOM_NullPtr *val)
Assignment operator
Destructor
~DOM_Document ()
Destructor
Factory methods to create new nodes for the Document
static DOM_Document createDocument ()
Create a new empty document
DOM_Entity createEntity (const DOMString &name)
Create a new entity
DOM_Element createElement (const DOMString &tagName)
Creates an element of the type specified
DOM_Element createElement (const XMLCh *tagName)
Creates an element of the type specified
DOM_DocumentFragment createDocumentFragment ()
Creates an empty DocumentFragment object
DOM_Text createTextNode (const DOMString &data)
Creates a Text node given the specified string
DOM_Comment createComment (const DOMString &data)
Creates a Comment node given the specified string
DOM_CDATASection createCDATASection (const DOMString &data)
Creates a CDATASection node whose value is the specified string
DOM_DocumentType createDocumentType (const DOMString &name)
Create a DocumentType node
DOM_Notation createNotation (const DOMString &name)
Create a Notation
DOM_ProcessingInstruction createProcessingInstruction (const DOMString &target, const DOMString &data)
Creates a ProcessingInstruction node given the specified name and data strings
DOM_Attr createAttribute (const DOMString &name)
Creates an Attr of the given name
DOM_EntityReference createEntityReference (const DOMString &name)
Creates an EntityReference object
static DOM_NodeIterator createNodeIterator (DOM_Node root, short whatToShow, DOM_NodeFilter filter)
Creates a NodeIterator object
static DOM_TreeWalker createTreeWalker (DOM_Node root, short whatToShow, DOM_NodeFilter filter)
Creates a TreeWalker object
Functions introduced in DOM Level 2.
DOM_Node importNode (const DOM_Node &source, bool deep)
Import a copy of a node from another document into this document
DOM_Element createElementNS (const DOMString &namespaceURI, const DOMString &qualifiedName)
Creates an element of the given qualified name and namespace URI
DOM_Attr createAttributeNS (const DOMString &namespaceURI, const DOMString &qualifiedName)
Creates an attribute of the given qualified name and namespace URI
DOM_NodeList getElementsByTagNameNS (const DOMString &namespaceURI, const DOMString &localName) const
Returns a DOM_NodeList of all the DOM_Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree
DOM_Element getElementById (const DOMString &elementId)
Returns the Element whose ID is given by elementId
Getter functions
DOM_DocumentType getDoctype () const
Get Document Type Declaration (see DOM_DocumentType) associated with this document
DOM_DOMImplementation& getImplementation () const
Return the DOMImplementation object that handles this document
DOM_Element getDocumentElement () const
Return a reference to the root element of the document
DOM_NodeList getElementsByTagName (const DOMString &tagname) const
Returns a DOM_NodeList of all the elements with a given tag name

Inherited from DOM_Node:

Public

Cloning function.

DOM_Node cloneNode(bool deep) const
Returns a duplicate of this node

Destructor.

~DOM_Node()
Destructor for DOM_Node

Equality and Inequality operators.

bool operator == (const DOM_Node & other) const
The equality operator
bool operator == (const DOM_NullPtr *other) const
Compare with a pointer
bool operator != (const DOM_Node & other) const
The inequality operator
bool operator != (const DOM_NullPtr * other) const
Compare with a pointer

Functions to modify the DOM Node.

DOM_Node insertBefore(const DOM_Node &newChild, const DOM_Node &refChild)
Inserts the node newChild before the existing child node refChild
DOM_Node replaceChild(const DOM_Node &newChild, const DOM_Node &oldChild)
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node
DOM_Node removeChild(const DOM_Node &oldChild)
Removes the child node indicated by oldChild from the list of children, and returns it
DOM_Node appendChild(const DOM_Node &newChild)
Adds the node newChild to the end of the list of children of this node

Get functions.

DOMString getNodeName() const
The name of this node, depending on its type; see the table above
DOMString getNodeValue() const
Gets the value of this node, depending on its type
short getNodeType() const
An enum value representing the type of the underlying object
DOM_Node getParentNode() const
Gets the parent of this node
DOM_NodeList getChildNodes() const
Gets a NodeList that contains all children of this node
DOM_Node getFirstChild() const
Gets the first child of this node
DOM_Node getLastChild() const
Gets the last child of this node
DOM_Node getPreviousSibling() const
Gets the node immediately preceding this node
DOM_Node getNextSibling() const
Gets the node immediately following this node
DOM_NamedNodeMap getAttributes() const
Gets a NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise
DOM_Document getOwnerDocument() const
Gets the Document object associated with this node
void* getUserData() const
Return the user data pointer

Query functions.

bool hasChildNodes() const
This is a convenience method to allow easy determination of whether a node has any children
bool isNull() const
Test whether this node is null

Set functions.

void setNodeValue(const DOMString &nodeValue)
Sets the value of the node
void setUserData(void *p)
Set the user data for a node

Documentation

Class to refer to XML Document nodes in the DOM. Conceptually, a DOM document node is the root of the document tree, and provides the primary access to the document's data.

Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.

Constructors and assignment operators

DOM_Document()
The default constructor for DOM_Document creates a null DOM_Document object that refers to no document. It may subsequently be assigned to refer to an actual Document node. To create a new document, use the static method DOM_Document::createDocument().

DOM_Document(const DOM_Document &other)
Copy constructor. Creates a new DOM_Document that refers to the same underlying actual document as the original.
Parameters:
other - The object to be copied

DOM_Document& operator = (const DOM_Document &other)
Assignment operator
Parameters:
other - The object to be copied

DOM_Document& operator = (const DOM_NullPtr *val)
Assignment operator. This overloaded variant is provided for the sole purpose of setting a DOM_Node reference variable to zero. Nulling out a reference variable in this way will decrement the reference count on the underlying Node object that the variable formerly referenced. This effect is normally obtained when reference variable goes out of scope, but zeroing them can be useful for global instances, or for local instances that will remain in scope for an extended time, when the storage belonging to the underlying node needs to be reclaimed.
Parameters:
val. - Only a value of 0, or null, is allowed.

Destructor

~DOM_Document()
Destructor. The object being destroyed is the reference object, not the underlying Document itself.

The reference counting memory management will delete the underlying document itself if this DOM_Document is the last remaining to refer to the Document, and if there are no remaining references to any of the nodes within the document tree. If other live references do remain, the underlying document itself remains also.

Factory methods to create new nodes for the Document

static DOM_Document createDocument()
Create a new empty document. This differs from the DOM_Document default constructor, which creates a null reference only, not an actual document.

This function is an extension to the DOM API, which lacks any mechanism for the creation of new documents.

Returns:
A new DOM_Document, which may then be populated using the DOM API calls.

DOM_Entity createEntity(const DOMString &name)
Create a new entity. Non-standard extension.
Parameters:
name - The name of the entity to instantiate

DOM_Element createElement(const DOMString &tagName)
Creates an element of the type specified. Note that the instance returned implements the Element interface, so attributes can be specified directly on the returned object.
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Returns:
A DOM_Element that reference the new element.
Parameters:
tagName - The name of the element type to instantiate.

DOM_Element createElement(const XMLCh *tagName)
Creates an element of the type specified. This non-standard overload of createElement, with the name specified as raw Unicode string, is intended for use from XML parsers, and is the best performing way to create elements. The name string is not checked for conformance to the XML rules for valid element names.
Returns:
A DOM_Element that reference the new element.
Parameters:
tagName - The name of the element type to instantiate, as a null-terminated unicode string.

DOM_DocumentFragment createDocumentFragment()
Creates an empty DocumentFragment object.
Returns:
A DOM_DocumentFragment that references the newly created document fragment.

DOM_Text createTextNode(const DOMString &data)
Creates a Text node given the specified string.
Returns:
A DOM_Text object that references the newly created text node.
Parameters:
data - The data for the node.

DOM_Comment createComment(const DOMString &data)
Creates a Comment node given the specified string.
Returns:
A DOM_Comment that references the newly created comment node.
Parameters:
data - The data for the comment.

DOM_CDATASection createCDATASection(const DOMString &data)
Creates a CDATASection node whose value is the specified string.
Throws:
DOMException NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Returns:
A DOM_CDATASection object.
Parameters:
data - The data for the DOM_CDATASection contents.

DOM_DocumentType createDocumentType(const DOMString &name)
Create a DocumentType node. Non-standard extension.
Returns:
A DOM_DocumentType that references the newly created DocumentType node.

DOM_Notation createNotation(const DOMString &name)
Create a Notation. Non-standard extension.
Returns:
A DOM_Notation that references the newly created Notation node.
Parameters:
name - The name of the notation to instantiate

DOM_ProcessingInstruction createProcessingInstruction(const DOMString &target, const DOMString &data)
Creates a ProcessingInstruction node given the specified name and data strings.
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if an invalid character is specified.
Returns:
A DOM_ProcessingInstruction that references the newly created PI node.
Parameters:
target - The target part of the processing instruction.
data - The data for the node.

DOM_Attr createAttribute(const DOMString &name)
Creates an Attr of the given name. Note that the Attr instance can then be attached to an Element using the DOMElement::setAttribute() method.
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Returns:
A DOM_Attr that references the newly created Attr.
Parameters:
name - The name of the attribute.

DOM_EntityReference createEntityReference(const DOMString &name)
Creates an EntityReference object.
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Returns:
A DOM_EntityReference that references the newly created EntityReference node.
Parameters:
name - The name of the entity to reference.

static DOM_NodeIterator createNodeIterator(DOM_Node root, short whatToShow, DOM_NodeFilter filter)
Creates a NodeIterator object. (DOM2)

static DOM_TreeWalker createTreeWalker(DOM_Node root, short whatToShow, DOM_NodeFilter filter)
Creates a TreeWalker object. (DOM2)

Getter functions

DOM_DocumentType getDoctype() const
Get Document Type Declaration (see DOM_DocumentType) associated with this document. For documents without a document type declaration this returns null reference object. The DOM Level 1 does not support editing the Document Type Declaration, therefore docType cannot be altered in any way.

DOM_DOMImplementation& getImplementation() const
Return the DOMImplementation object that handles this document

DOM_Element getDocumentElement() const
Return a reference to the root element of the document

DOM_NodeList getElementsByTagName(const DOMString &tagname) const
Returns a DOM_NodeList of all the elements with a given tag name. The returned node list is "live", in that changes to the document tree made after a nodelist was initially returned will be immediately reflected in the node list. The elements in the node list are ordered in the same order in which they would be encountered in a preorder traversal of the Document tree.
Returns:
A reference to a NodeList containing all the matched Elements.
Parameters:
tagname - The name of the tag to match on. The special value "*" matches all tags.

Functions introduced in DOM Level 2.

DOM_Node importNode(const DOM_Node &source, bool deep)
Import a copy of a node from another document into this document. The source node, which may belong to a different document, is copied, with the copy belonging to this document. The copy is not placed into the document (the parent node is null).
Returns:
The newly created copy of the source node, belonging to this document
Parameters:
deep - If true, recursively import the subtree under the specified node; if flase, import only the node itself (and its attributes, if if is a DOM_Element.

DOM_Element createElementNS(const DOMString &namespaceURI, const DOMString &qualifiedName)
Creates an element of the given qualified name and namespace URI
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Returns:
A new DOM_Element object.
Parameters:
namespaceURI - The namespace URI of the element to create. When it is null or an empty string, this method behaves like createElement.
qualifiedName - The qualified name of the element type to instantiate.

DOM_Attr createAttributeNS(const DOMString &namespaceURI, const DOMString &qualifiedName)
Creates an attribute of the given qualified name and namespace URI
Throws:
DOMException INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Returns:
A new DOM_Attr object.
Parameters:
namespaceURI - The namespace URI of the attribute to create. When it is null or an empty string, this method behaves like createAttribute.
qualifiedName - The qualified name of the attribute type to instantiate.

DOM_NodeList getElementsByTagNameNS(const DOMString &namespaceURI, const DOMString &localName) const
Returns a DOM_NodeList of all the DOM_Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree
Returns:
A new DOM_NodeList object containing all the matched Elements.
Parameters:
namespaceURI - The namespace URI of the elements to match on. The special value "*" matches all namespaces. When it is null or an empty string, this method behaves like getElementsByTagName.
localName - The local name of the elements to match on. The special value "*" matches all local names.

DOM_Element getElementById(const DOMString &elementId)
Returns the Element whose ID is given by elementId. If no such element exists, returns null. Behavior is not defined if more than one element has this ID.
Returns:
The matching element.
Parameters:
elementId - The unique id value for an element.


This class has no child classes.

alphabetic index hierarchy of classes


XML Parser for C++ 2.0
Copyright © IBM Corp, 1999
Center for Java Technology
10275 N. De Anza Blvd.
Cupertino CA 95014 USA
Email: xml4c@us.ibm.com

IBM Logo