ClanLib
2.3.7
|
DOM Document class. More...
#include <dom_document.h>
Public Member Functions | |
Construction | |
CL_DomDocument () | |
Constructs a DOM Document. More... | |
CL_DomDocument (CL_IODevice &input, bool eat_whitespace=true) | |
Constructs a DomDocument. More... | |
CL_DomDocument (const CL_DomString &namespace_uri, const CL_DomString &qualified_name, const CL_DomDocumentType &doctype) | |
CL_DomDocument (const CL_SharedPtr< CL_DomNode_Generic > &impl) | |
Constructs a DomDocument. More... | |
~CL_DomDocument () | |
Attributes | |
CL_DomDocumentType | get_doctype () |
Returns the Document Type Declaration (see CL_DomDocumentType)associated with this document. More... | |
CL_DomImplementation | get_implementation () |
Returns the CL_DomImplementation object that handles this document. More... | |
CL_DomElement | get_document_element () |
Returns the root document element node. More... | |
Operations | |
CL_DomElement | create_element (const CL_DomString &tag_name) |
Creates an element of the type specified. More... | |
CL_DomElement | create_element_ns (const CL_DomString &namespace_uri, const CL_DomString &qualified_name) |
Creates an element of the given qualified name and namespace URI. More... | |
CL_DomDocumentFragment | create_document_fragment () |
Creates an empty DocumentFragment object. More... | |
CL_DomText | create_text_node (const CL_DomString &data) |
Creates a Text node given the specified string. More... | |
CL_DomComment | create_comment (const CL_DomString &data) |
Creates a Comment node given the specified string. More... | |
CL_DomCDATASection | create_cdata_section (const CL_DomString &data) |
Creates a CDATASection node whose value is the specified string. More... | |
CL_DomProcessingInstruction | create_processing_instruction (const CL_DomString &target, const CL_DomString &data) |
Creates a ProcessingInstruction node given the specified name and data strings. More... | |
CL_DomAttr | create_attribute (const CL_DomString &name) |
Creates an Attr of the given name. More... | |
CL_DomAttr | create_attribute_ns (const CL_DomString &namespace_uri, const CL_DomString &qualified_name) |
Creates an attribute of the given qualified name and namespace URI. More... | |
CL_DomEntityReference | create_entity_reference (const CL_DomString &name) |
Creates an EntityReference object. More... | |
CL_DomNodeList | get_elements_by_tag_name (const CL_DomString &tag_name) |
Returns a NodeList of all the Elements with a given tag name. More... | |
CL_DomNodeList | get_elements_by_tag_name_ns (const CL_DomString &namespace_uri, const CL_DomString &qualified_name) |
Returns a NodeList of all the Elements with a given local name and namespace URI. More... | |
CL_DomElement | get_element_by_id (const CL_DomString &element_id) |
Returns the Element whose ID is given by element_id. More... | |
CL_DomNode | import_node (const CL_DomNode &node, bool deep) |
Imports a node from another document to this document. More... | |
std::vector< CL_DomNode > | load (CL_IODevice &input, bool eat_whitespace=true, CL_DomNode insert_point=CL_DomNode()) |
Loads the DOM document as XML from an input source. More... | |
void | save (CL_IODevice &output, bool insert_whitespace=true) |
Saves the DOM document as XML to an input source. More... | |
void | clear_all () |
Removes all nodes from the DOM document. More... | |
Operations | |
bool | operator== (const CL_DomNode &other) const |
Compare operator. More... | |
bool | operator!= (const CL_DomNode &other) const |
Compare operator. More... | |
void | normalize () |
Merges any adjacent Text nodes. More... | |
CL_DomNode | insert_before (CL_DomNode &new_child, CL_DomNode &ref_child) |
Inserts the node new_child before the existing child node ref_child. More... | |
CL_DomNode | replace_child (CL_DomNode &new_child, CL_DomNode &old_child) |
Replaces the child node old_child with new_child in the list of children. More... | |
CL_DomNode | remove_child (CL_DomNode &old_child) |
Removes the child node indicated by old_child from the list of children, and returns it. More... | |
CL_DomNode | append_child (CL_DomNode new_child) |
Adds the node new_child to the end of the list of children of this node. More... | |
CL_DomNode | clone_node (bool deep) const |
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. More... | |
CL_DomElement | to_element () const |
Returns the Element interface to this node. More... | |
CL_DomAttr | to_attr () const |
Returns the Attribute interface to this node. More... | |
CL_DomText | to_text () const |
Returns the Text interface to this node. More... | |
CL_DomCDATASection | to_cdata_section () const |
Returns the CDATA Section interface to this node. More... | |
CL_DomEntityReference | to_entity_reference () const |
Returns the Entity Reference interface to this node. More... | |
CL_DomEntity | to_entity () const |
Returns the Entity interface to this node. More... | |
CL_DomProcessingInstruction | to_processing_instruction () const |
Returns the Processing Instruction interface to this node. More... | |
CL_DomComment | to_comment () const |
Returns the Comment interface to this node. More... | |
CL_DomDocument | to_document () const |
Returns the Document interface to this node. More... | |
CL_DomDocumentType | to_document_type () const |
Returns the Document Type interface to this node. More... | |
CL_DomDocumentFragment | to_document_fragment () const |
Returns the Document Fragment interface to this node. More... | |
CL_DomNotation | to_notation () const |
Returns the Notation interface to this node. More... | |
CL_DomNode | named_item (const CL_DomString &name) const |
Returns the first child node with the specified node name. More... | |
CL_DomNode | named_item_ns (const CL_DomString &namespace_uri, const CL_DomString &local_name) const |
Retrieves the first child node with the specified namespace URI and local name. More... | |
CL_DomString | find_namespace_uri (const CL_DomString &qualified_name) const |
Searches the node tree upwards for the namespace URI of the given qualified name. More... | |
CL_DomString | find_prefix (const CL_DomString &namespace_uri) const |
Searches the node tree upwards for the prefix name for the namespace URI. More... | |
std::vector< CL_DomNode > | select_nodes (const CL_DomString &xpath_expression) const |
Returns all the nodes matching the specified xpath expression using this node as the context node. More... | |
CL_DomNode | select_node (const CL_DomString &xpath_expression) const |
Returns the first node matching the specified xpath expression using this node as the context node. More... | |
CL_String | select_string (const CL_DomString &xpath_expression) const |
Returns the first node value matching the specified xpath expression using this node as the context node. More... | |
int | select_int (const CL_DomString &xpath_expression) const |
Returns the first node value (as integer) matching the specified xpath expression using this node as the context node. More... | |
float | select_float (const CL_DomString &xpath_expression) const |
Returns the first node value (as float) matching the specified xpath expression using this node as the context node. More... | |
bool | select_bool (const CL_DomString &xpath_expression) const |
Returns the first node value (as boolean) matching the specified xpath expression using this node as the context node. More... | |
Protected Attributes | |
Implementation | |
CL_SharedPtr< CL_DomNode_Generic > | impl |
Attributes | |
CL_DomString | get_node_name () const |
Returns the node name. More... | |
CL_DomString | get_namespace_uri () const |
Returns the namespace URI of this node. More... | |
CL_DomString | get_prefix () const |
Returns the namespace prefix of the node. More... | |
void | set_prefix (const CL_DomString &prefix) |
Sets the namespace prefix of the node. More... | |
CL_DomString | get_local_name () const |
Returns local part of the qualified name of this node. More... | |
CL_DomString | get_node_value () const |
Returns the node value. More... | |
void | set_node_value (const CL_DomString &value) |
Sets the node value. More... | |
unsigned short | get_node_type () const |
Returns the node type (one of those in the NodeType enum). More... | |
CL_DomNode | get_parent_node () const |
Returns the parent of this node. More... | |
CL_DomNodeList | get_child_nodes () const |
Returns a NodeList that contains all children of this node. More... | |
CL_DomNode | get_first_child () const |
The first child of this node. More... | |
CL_DomNode | get_last_child () const |
The last child of this node. More... | |
CL_DomNode | get_previous_sibling () const |
The node immediately preceding this node. More... | |
CL_DomNode | get_next_sibling () const |
The node immediately following this node. More... | |
CL_DomNamedNodeMap | get_attributes () const |
A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise. More... | |
CL_DomDocument | get_owner_document () const |
The Document object associated with this node. More... | |
bool | is_null () const |
Returns true if this is a null node. More... | |
bool | is_element () const |
Returns true if this is an element node. More... | |
bool | is_attr () const |
Returns true if this is an attribute node. More... | |
bool | is_text () const |
Returns true if this is a text node. More... | |
bool | is_cdata_section () const |
Returns true if this is a CDATA section node. More... | |
bool | is_entity_reference () const |
Returns true if this is an entity reference node. More... | |
bool | is_entity () const |
Returns true if this is an entity node. More... | |
bool | is_processing_instruction () const |
Returns true if this is a processing instruction node. More... | |
bool | is_comment () const |
Returns true if this is a comment node. More... | |
bool | is_document () const |
Returns true if this is a document node. More... | |
bool | is_document_type () const |
Returns true if this is a document type node. More... | |
bool | is_document_fragment () const |
Returns true if this is a document fragment node. More... | |
bool | is_notation () const |
Returns true if this is a notation node. More... | |
bool | is_supported (const CL_DomString &feature, const CL_DomString &version) const |
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node. More... | |
bool | has_attributes () const |
Returns true if this node (if its an element) has any attributes. More... | |
bool | has_child_nodes () const |
Returns true if this node has any children. More... | |
enum | NodeType { NULL_NODE = 0, ELEMENT_NODE = 1, ATTRIBUTE_NODE = 2, TEXT_NODE = 3, CDATA_SECTION_NODE = 4, ENTITY_REFERENCE_NODE = 5, ENTITY_NODE = 6, PROCESSING_INSTRUCTION_NODE = 7, COMMENT_NODE = 8, DOCUMENT_NODE = 9, DOCUMENT_TYPE_NODE = 10, DOCUMENT_FRAGMENT_NODE = 11, NOTATION_NODE = 12 } |
An integer indicating which type of node this is. More... | |
DOM Document class.
The Document interface represents the entire HTML or XML document. Conceptually, it 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.
|
inherited |
CL_DomDocument::CL_DomDocument | ( | ) |
Constructs a DOM Document.
CL_DomDocument::CL_DomDocument | ( | CL_IODevice & | input, |
bool | eat_whitespace = true |
||
) |
Constructs a DomDocument.
input | = IODevice |
eat_whitespace | = bool |
CL_DomDocument::CL_DomDocument | ( | const CL_DomString & | namespace_uri, |
const CL_DomString & | qualified_name, | ||
const CL_DomDocumentType & | doctype | ||
) |
CL_DomDocument::CL_DomDocument | ( | const CL_SharedPtr< CL_DomNode_Generic > & | impl) |
Constructs a DomDocument.
impl | = Shared Ptr |
CL_DomDocument::~CL_DomDocument | ( | ) |
|
inherited |
Adds the node new_child to the end of the list of children of this node.
If the new_child is already in the tree, it is first removed.
void CL_DomDocument::clear_all | ( | ) |
Removes all nodes from the DOM document.
|
inherited |
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
The duplicate node has no parent.
Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a child Text node. Cloning any other type of node simply returns a copy of this node.
deep | If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element). retval: The duplicate node. |
CL_DomAttr CL_DomDocument::create_attribute | ( | const CL_DomString & | name) |
Creates an Attr of the given name.
Note that the Attr instance can then be set on an Element using the setAttribute method.
name | The name of the attribute. |
CL_DomAttr CL_DomDocument::create_attribute_ns | ( | const CL_DomString & | namespace_uri, |
const CL_DomString & | qualified_name | ||
) |
Creates an attribute of the given qualified name and namespace URI.
Note that the Attr instance can then be set on an Element using the setAttribute method.
CL_DomCDATASection CL_DomDocument::create_cdata_section | ( | const CL_DomString & | data) |
Creates a CDATASection node whose value is the specified string.
data | The data for the CDATASection contents. |
CL_DomComment CL_DomDocument::create_comment | ( | const CL_DomString & | data) |
Creates a Comment node given the specified string.
data | The data for the node. |
CL_DomDocumentFragment CL_DomDocument::create_document_fragment | ( | ) |
Creates an empty DocumentFragment object.
CL_DomElement CL_DomDocument::create_element | ( | const CL_DomString & | tag_name) |
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.
tag_name | The name of the element type to instantiate. For XML, this is case-sensitive. |
CL_DomElement CL_DomDocument::create_element_ns | ( | const CL_DomString & | namespace_uri, |
const CL_DomString & | qualified_name | ||
) |
Creates an element of the given qualified name and namespace URI.
CL_DomEntityReference CL_DomDocument::create_entity_reference | ( | const CL_DomString & | name) |
Creates an EntityReference object.
name | The name of the entity to reference. |
CL_DomProcessingInstruction CL_DomDocument::create_processing_instruction | ( | const CL_DomString & | target, |
const CL_DomString & | data | ||
) |
Creates a ProcessingInstruction node given the specified name and data strings.
target | The target part of the processing instruction. |
data | The data for the node. |
CL_DomText CL_DomDocument::create_text_node | ( | const CL_DomString & | data) |
Creates a Text node given the specified string.
data | The data for the node. |
|
inherited |
Searches the node tree upwards for the namespace URI of the given qualified name.
|
inherited |
Searches the node tree upwards for the prefix name for the namespace URI.
|
inherited |
A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
|
inherited |
Returns a NodeList that contains all children of this node.
If there are no children, this is a NodeList containing no nodes. The content of the returned NodeList is "live" in the sense that, for instance, changes to the children of the node object that it was created from are immediately reflected in the nodes returned by the NodeList accessors; it is not a static snapshot of the content of the node. This is true for every NodeList, including the ones returned by the getElementsByTagName method.
CL_DomDocumentType CL_DomDocument::get_doctype | ( | ) |
Returns the Document Type Declaration (see CL_DomDocumentType)associated with this document.
For HTML documents as well as XML documents without a document type declaration this returns null. The DOM Level 1 does not support editing the Document Type Declaration, therefore docType cannot be altered in any way.
CL_DomElement CL_DomDocument::get_document_element | ( | ) |
Returns the root document element node.
This is a convenience attribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tag name "HTML".
CL_DomElement CL_DomDocument::get_element_by_id | ( | const CL_DomString & | element_id) |
Returns the Element whose ID is given by element_id.
CL_DomNodeList CL_DomDocument::get_elements_by_tag_name | ( | const CL_DomString & | tag_name) |
Returns a NodeList of all the Elements with a given tag name.
The list is in the order in which they would be encountered in a preorder traversal of the Document tree.
tag_name | The name of the tag to match on. The special value "*" matches all tags. |
CL_DomNodeList CL_DomDocument::get_elements_by_tag_name_ns | ( | const CL_DomString & | namespace_uri, |
const CL_DomString & | qualified_name | ||
) |
Returns a NodeList of all the Elements with a given local name and namespace URI.
The list is in the order in which they would be encountered in a preorder traversal of the Document tree.
|
inherited |
The first child of this node.
If there is no such node, this returns a null node.
CL_DomImplementation CL_DomDocument::get_implementation | ( | ) |
Returns the CL_DomImplementation object that handles this document.
|
inherited |
The last child of this node.
If there is no such node, this returns a null node.
|
inherited |
Returns local part of the qualified name of this node.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as create_element from the Document interface, this is always an empty string.
|
inherited |
Returns the namespace URI of this node.
|
inherited |
The node immediately following this node.
If there is no such node, this returns a null node.
|
inherited |
Returns the node name.
The return value vary according to the node type as follows:
|
inherited |
Returns the node type (one of those in the NodeType enum).
|
inherited |
Returns the node value.
The return value vary according to the node type as follows:
|
inherited |
The Document object associated with this node.
This is also the Document object used to create new nodes. When this node is a Document this is null.
|
inherited |
Returns the parent of this node.
All nodes, except Document, DocumentFragment, and Attr may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.
|
inherited |
Returns the namespace prefix of the node.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as create_element from the Document interface, this is always an empty string.
|
inherited |
The node immediately preceding this node.
If there is no such node, this returns a null node.
|
inherited |
Returns true if this node (if its an element) has any attributes.
|
inherited |
Returns true if this node has any children.
CL_DomNode CL_DomDocument::import_node | ( | const CL_DomNode & | node, |
bool | deep | ||
) |
Imports a node from another document to this document.
The returned node has no parent. The source node is not altered or removed from the original document; this method creates a new copy of the source node.
For all nodes, importing a node creates a node object owned by the importing document, with attribute values identical to the source node's node_name and node_type, plus the attributes related to namespaces (prefix, local_name, and namespace_uri). As in the clone_node operation on a Node, the source node is not altered.
|
inherited |
Inserts the node new_child before the existing child node ref_child.
If refChild is a null node, inserts new_child at the end of the list of children.
If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before ref_child. If the new_child is already in the tree, it is first removed.
new_child | The node to insert. |
ref_child | The reference node, i.e., the node before which the new node must be inserted. retval: The node being inserted. |
|
inherited |
Returns true if this is an attribute node.
|
inherited |
Returns true if this is a CDATA section node.
|
inherited |
Returns true if this is a comment node.
|
inherited |
Returns true if this is a document node.
|
inherited |
Returns true if this is a document fragment node.
|
inherited |
Returns true if this is a document type node.
|
inherited |
Returns true if this is an element node.
|
inherited |
Returns true if this is an entity node.
|
inherited |
Returns true if this is an entity reference node.
|
inherited |
Returns true if this is a notation node.
|
inherited |
Returns true if this is a null node.
|
inherited |
Returns true if this is a processing instruction node.
|
inherited |
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
|
inherited |
Returns true if this is a text node.
std::vector<CL_DomNode> CL_DomDocument::load | ( | CL_IODevice & | input, |
bool | eat_whitespace = true , |
||
CL_DomNode | insert_point = CL_DomNode() |
||
) |
Loads the DOM document as XML from an input source.
input | Input source to read from. |
eat_whitespace | Passed on to CL_XMLTokenizer::set_eat_whitespace. |
insert_point | Place in the DOM to insert the loaded XML code. |
|
inherited |
Returns the first child node with the specified node name.
Returns a null node if no child is found.
|
inherited |
Retrieves the first child node with the specified namespace URI and local name.
|
inherited |
Merges any adjacent Text nodes.
Puts all Text nodes in the full depth of the sub-tree underneath this node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.
Note: In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.
|
inherited |
Compare operator.
|
inherited |
Compare operator.
|
inherited |
Removes the child node indicated by old_child from the list of children, and returns it.
|
inherited |
Replaces the child node old_child with new_child in the list of children.
If the new_child is already in the tree, it is first removed.
new_child | The new node to put in the child list. |
old_child | The node being replaced in the list. retval: The node replaced. |
void CL_DomDocument::save | ( | CL_IODevice & | output, |
bool | insert_whitespace = true |
||
) |
Saves the DOM document as XML to an input source.
output | Output source to write to. |
insert_whitespace | Passed on to CL_XMLWriter::set_insert_whitespace. |
|
inherited |
Returns the first node value (as boolean) matching the specified xpath expression using this node as the context node.
|
inherited |
Returns the first node value (as float) matching the specified xpath expression using this node as the context node.
|
inherited |
Returns the first node value (as integer) matching the specified xpath expression using this node as the context node.
|
inherited |
Returns the first node matching the specified xpath expression using this node as the context node.
|
inherited |
Returns all the nodes matching the specified xpath expression using this node as the context node.
|
inherited |
Returns the first node value matching the specified xpath expression using this node as the context node.
|
inherited |
Sets the node value.
|
inherited |
Sets the namespace prefix of the node.
Note that setting this attribute, when permitted, changes the node_name attribute, which holds the qualified name, as well as the tag_name and name attributes of the Element and Attr interfaces, when applicable.
Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since the namespace_uri and local_name do not change.
|
inherited |
Returns the Attribute interface to this node.
If the node is not an Attribute node, then it returns a null node.
|
inherited |
Returns the CDATA Section interface to this node.
If the node is not a CDATA Section node, then it returns a null node.
|
inherited |
Returns the Comment interface to this node.
If the node is not a Comment node, then it returns a null node.
|
inherited |
Returns the Document interface to this node.
If the node is not a Document node, then it returns a null node.
|
inherited |
Returns the Document Fragment interface to this node.
If the node is not a DocumentFragment node, then it returns a null node.
|
inherited |
Returns the Document Type interface to this node.
If the node is not a Document Type node, then it returns a null node.
|
inherited |
Returns the Element interface to this node.
If the node is not an Element node, then it returns a null node.
|
inherited |
Returns the Entity interface to this node.
If the node is not an Entity node, then it returns a null node.
|
inherited |
Returns the Entity Reference interface to this node.
If the node is not an Entity Reference node, then it returns a null node.
|
inherited |
Returns the Notation interface to this node.
If the node is not a Notation node, then it returns a null node.
|
inherited |
Returns the Processing Instruction interface to this node.
If the node is not a Processing Instrucion node, then it returns a null node.
|
inherited |
Returns the Text interface to this node.
If the node is not a Text node, then it returns a null node.
|
protectedinherited |