|
bool | operator== (const Node &other) const |
| Comparing Nodes for equality means asking if the two Node handles are referring to exactly the same object; two different nodes that happen to have the same properties will not test equal by this criteria. More...
|
|
bool | operator!= (const Node &other) const |
| Inequality test using same criteria as operator==(). More...
|
|
|
These methods are mostly used by the derived node classes; Nodes are not generally created directly in user code.
|
| Node () |
| Create an empty Node handle that can be used to hold a reference to any kind of Node. More...
|
|
| Node (const Node &src) |
| Copy constructor is shallow; that is, this handle will refer to the same node as the source. More...
|
|
Node & | operator= (const Node &src) |
| Copy assignment is shallow; the handle is first cleared and then will refer to the same node as the source. More...
|
|
Node | clone () const |
| The clone() method makes a deep copy of this Node and its children and returns a new orphan Node with the same contents; ordinary assignment and copy construction is shallow. More...
|
|
| ~Node () |
| The Node handle destructor does not recover heap space so if you create orphan nodes and then don't put them in a document there will be a memory leak unless you explicitly destruct them first with clearOrphan(). More...
|
|
void | clear () |
| This method restores the Node handle to its default-constructed state but does not recover any heap space; use clearOrphan() if you know this node was never put into a document. More...
|
|
void | clearOrphan () |
| This method explicitly frees the heap space for an orphan node that was created but never inserted into a document. More...
|
|
|
You can find out what concrete type of node this abstract Node handle is referring to (if any), who owns the node, and if it is owned by a parent element you can get access to the parent.
|
NodeType | getNodeType () const |
| Get the Xml::NodeType of this node. More...
|
|
String | getNodeTypeAsString () const |
| Get the Node type as a string; an empty handle returns "NoNode". More...
|
|
bool | isValid () const |
| Return true if this Node handle is referencing some node, false if the Node handle is empty. More...
|
|
bool | isTopLevelNode () const |
| Return true if this Node is owned by the top-level Xml document, false if the Node is owned by an Element or is an orphan, or if the Node handle is empty. More...
|
|
bool | isOrphan () const |
| Return true if this Node is an orphan, meaning that it is not empty, but is not owned by any element or top-level document. More...
|
|
bool | hasParentElement () const |
| Return true if this node has a parent, i.e. More...
|
|
Element | getParentElement () |
| Return a handle referencing this node's parent if it has one, otherwise throws an error; check first with hasParentElement() if you aren't sure. More...
|
|
|
Usually contents inspection is handled at the concrete node class level; here we can only provide information for which you don't need to know what kind of node this is.
|
const String & | getNodeText () const |
| Return a text value associated with this Node (not including its child nodes if any); the behavior depends on the NodeType. More...
|
|
void | writeToString (String &out, bool compact=false) const |
| Serialize this node (and everything it contains) to the given String. More...
|
|
Abstract handle for holding any kind of node in an XML tree.
The concrete node handle types derived from Node are: Comment, Unknown, Text, and Element. Only an Element node may contain other nodes.
A node may be classified by who owns it. There are three possibilities:
- Top-level node: The node belongs to the top-level Xml document and does not have a parent node.
- Child node: The node belongs to an element, which may be the root element or any lower-level element. The element that owns it is its "parent".
- Orphan node: The node is not yet part of any Xml document and does not belong to an element. In that case the Node handle serves as the owner and the node does not have a parent node.
A Node handle may also be empty, meaning it refers to no node at all so there is nothing to own.
Top-level nodes can only be Comment nodes, Unknown nodes, or the lone root Element node. Child nodes and orphans can be of Element and Text type also. Normally orphans exist only briefly during the time a new node is constructed and the time it is adopted by some element (usually in the same constructor) so you can ignore them for the most part. But if you must keep orphan nodes around, be aware that they must be referenced by only one handle at a time to avoid ownership conflicts.