Abstract handle for holding any kind of node in an XML tree. More...
#include <Xml.h>
Public Member Functions | |
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. | |
bool | operator!= (const Node &other) const |
Inequality test using same criteria as operator==(). | |
Construction and destruction | |
Node () | |
Create an empty Node handle that can be used to hold a reference to any kind of Node. | |
Node (const Node &src) | |
Copy constructor is shallow; that is, this handle will refer to the same node as the source. | |
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. | |
~Node () | |
The Node handle destructor usually does nothing but if it is referencing an orphan node then it will delete the orphan here; make sure you never have two handles referencing an orphan because they are not reference-counted. | |
void | clear () |
This method clears the Node handle, deleting the contents if the Node was an orphan and restoring the Node handle to its default-constructed state. | |
Node classification | |
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. | |
String | getNodeTypeAsString () const |
Get the Node type as a string; an empty handle returns "NoNode". | |
bool | isValid () const |
Return true if this Node handle is referencing some node, false if the Node handle is empty. | |
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. | |
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. | |
bool | hasParentElement () const |
Return true if this node has a parent, i.e. | |
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. | |
Access to node contents | |
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. | |
void | writeToString (String &out, bool compact=false) const |
Serialize this node (and everything it contains) to the given String. | |
Friends | |
class | Xml |
class | Xml::Impl |
class | Xml::node_iterator |
class | Xml::Comment |
class | Xml::Unknown |
class | Xml::Text |
class | Xml::Element |
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:
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.
Node | ( | ) | [inline] |
Copy constructor is shallow; that is, this handle will refer to the same node as the source.
Note that this handle will provide write access to the underlying node, even if the source was const.
~Node | ( | ) | [inline] |
The Node handle destructor usually does nothing but if it is referencing an orphan node then it will delete the orphan here; make sure you never have two handles referencing an orphan because they are not reference-counted.
void clear | ( | ) |
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.
This is a convenience that saves downcasting a generic Node to a concrete type when all you want to do is dump out the text. It is not particularly useful for Element nodes. Here is what you get for each type of node:
NodeType getNodeType | ( | ) | const |
Get the Xml::NodeType of this node.
If this Node handle is empty, the returned NodeType will be "Xml::NoNode".
String getNodeTypeAsString | ( | ) | const |
Get the Node type as a string; an empty handle returns "NoNode".
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.
bool hasParentElement | ( | ) | const |
Return true if this node has a parent, i.e.
it is owned by an element; the root element and other top-level nodes are owned by the document and thus do not have a parent.
bool isOrphan | ( | ) | const |
bool isTopLevelNode | ( | ) | const |
bool isValid | ( | ) | const [inline] |
Return true if this Node handle is referencing some node, false if the Node handle is empty.
Referenced by Element::getOptionalElementValue(), and Element::getOptionalElementValueAs().
bool operator!= | ( | const Node & | other | ) | const [inline] |
Inequality test using same criteria as operator==().
Copy assignment is shallow; the handle is first cleared and then will refer to the same node as the source.
Note that this handle will provide write access to the underlying node even if the source handle was const.
bool operator== | ( | const Node & | other | ) | const [inline] |
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.
void writeToString | ( | String & | out, | |
bool | compact = false | |||
) | const |
Serialize this node (and everything it contains) to the given String.
The output will be "pretty printed" and terminated with a newline unless you specify compact = true in which case indents and newlines will be suppressed.
friend class Xml [friend] |
friend class Xml::Comment [friend] |
friend class Xml::Element [friend] |
friend class Xml::Impl [friend] |
friend class Xml::node_iterator [friend] |
friend class Xml::Text [friend] |
friend class Xml::Unknown [friend] |