|
#include <CXmlNode.h>

Public Types | |
| enum | CXmlNodeType { DOM_UNDEFINED = 0, DOM_DOCUMENT = 1, DOM_ELEMENT = 2, DOM_PI = 4, DOM_TEXT = 8, DOM_CDATA_SECTION = 16, DOM_COMMENT = 32, DOM_ATTRIBUTE = 64 } |
| Node type enumeration. More... | |
| typedef CXmlNodeList::iterator | iterator |
| CXmlNode own iterator for subnodes. | |
|
typedef CXmlNodeList::const_iterator | const_iterator |
| CXmlNode own const_iterator for subnodes. | |
Public Member Functions | |
| CXmlNode * | findFirst (std::string name, bool recursively=true) const |
| Finds the first subnode with the given name. | |
| CXmlNode * | findOrCreate (std::string name, bool recursively=true) |
| Finds the first subnode with the given name, or creates a new one. | |
| CXmlNode & | operator[] (std::string name) |
| Finds the first subnode with the given name, or creates a new one. | |
| virtual CXmlNodeType | type () const =0 |
| Returns node type. | |
| void | select (CXmlNodeVector &nodes, std::string xpath) |
| Selects nodes as defined by XPath. | |
| virtual void | copy (const CXmlNode &node) |
| Performs a deep copy of node and all its subnodes. | |
| virtual void | clearChildren () |
| Deletes all child nodes. | |
| virtual void | clear () |
| Deletes all children and clears all the attributes. | |
| CXmlNode * | parent () const |
| Returns parent node of this node. | |
| CXmlDoc * | document () const |
| Returns document context associated with this node. | |
| virtual const std::string & | name () const =0 |
| Returns the node name. | |
| virtual void | name (const std::string &name)=0 |
| Sets the new name for the node. | |
| virtual void | name (const char *name)=0 |
| Sets new name for node. | |
| virtual const std::string & | value () const |
| Returns the value of the node. | |
| virtual void | value (const std::string &new_value) |
| Sets new value to node. | |
| virtual void | value (const char *new_value) |
| Sets new value to node. | |
| std::string | text () const |
| Returns cdatas combined from children. | |
| void | text (std::string txt) |
| Sets text for the node. | |
| virtual CXmlAttributes & | attributes () |
| Returns referrence to node attributes. | |
| virtual const CXmlAttributes & | attributes () const |
| Returns referrence to node attributes (const version). | |
| virtual bool | hasAttributes () const |
| Returns true, if node has any attributes. | |
| virtual bool | hasAttribute (const char *attr) const |
| virtual CXmlValue | getAttribute (std::string attr, const char *defaultValue="") const |
| virtual void | setAttribute (const char *attr, CXmlValue value, const char *defaultValue="") |
| virtual void | setAttribute (const std::string &attr, CXmlValue value, const char *defaultValue="") |
| virtual void | save (CBuffer &buffer, int indent=0) const |
| virtual iterator | begin () |
| Returns the first subnode iterator. | |
| virtual const_iterator | begin () const |
| Returns the first subnode const iterator. | |
| virtual iterator | end () |
| Returns the end subnode iterator. | |
| virtual const_iterator | end () const |
| Returns the end subnode const iterator. | |
| virtual uint32_t | size () const |
| Returns a number of subnodes. | |
| virtual bool | empty () const |
| Returns true if node has no subnodes of subnodes. | |
| virtual void | push_back (CXmlNode *node) |
| Appends a subnode. | |
| virtual void | insert (iterator pos, CXmlNode *node) |
| Inserts a subnode. | |
| virtual void | remove (CXmlNode *node) |
| Removes a subnode. | |
| virtual void | unlink (CXmlNode *node) |
| Removes a subnode. | |
| bool | isDocument () const |
| Document node, can contain subnodes and attributes. | |
| bool | isElement () const |
| Normal element node or document, can contain subnodes and attributes. | |
| bool | isPI () const |
| Processing Instruction node. | |
| bool | isText () const |
| Cdata where all default entities MUST be escaped. | |
| bool | isCDataSection () const |
| Cdata section, which can contain preformatted char data. | |
| bool | isComment () const |
| Comment node. | |
Protected Member Functions | |
| virtual bool | nameIs (const std::string *sstName) const |
| Always returns false for CXmlNode since it has no name. | |
| CXmlNode (CXmlDoc &doc) | |
| Protected constructor - for derived classes. | |
| CXmlNode (CXmlNode &parent) | |
| Protected constructor - for derived classes. | |
| virtual | ~CXmlNode () |
| Destructor. | |
Protected Attributes | |
| CXmlDoc * | m_document |
| Parent document pointer. | |
| CXmlNode * | m_parent |
| Parent node pointer. | |
Static Protected Attributes | |
| static CXmlNodeList | emptyNodes |
| An empty nodes set to emulate a set of stub iterators. | |
| static const std::string | emptyString |
| An empty string to use as a stub for value(). | |
Friends | |
| class | CXmlParser |
| class | CXmlNodeList |
| class | CXmlDoc |
| class | CXmlElement |
| class | CXmlAttribute |
| class | CXmlAttributes |
Basic class for any XML node
Node type enumeration.
| sptk::CXmlNode::CXmlNode | ( | CXmlDoc & | doc | ) | [inline, protected] |
| sptk::CXmlNode::CXmlNode | ( | CXmlNode & | parent | ) | [inline, protected] |
Protected constructor - for derived classes.
| parent | CXmlNode&, node document |
References document(), and push_back().
| virtual const CXmlAttributes& sptk::CXmlNode::attributes | ( | ) | const [inline, virtual] |
Returns referrence to node attributes (const version).
Returns 0 if node isn't CXmlElement or CXmlDocument
Reimplemented in sptk::CXmlElement.
| virtual CXmlAttributes& sptk::CXmlNode::attributes | ( | ) | [inline, virtual] |
Returns referrence to node attributes.
Returns 0 if node isn't CXmlElement or CXmlDocument
Reimplemented in sptk::CXmlElement.
| virtual void sptk::CXmlNode::clear | ( | ) | [inline, virtual] |
Deletes all children and clears all the attributes.
Any memory, associated with children or attributes, is released.
Reimplemented in sptk::CXmlDoc, and sptk::CXmlElement.
| virtual void sptk::CXmlNode::clearChildren | ( | ) | [inline, virtual] |
Deletes all child nodes.
Any memory, associated with child nodes is released.
Reimplemented in sptk::CXmlElement.
| virtual void sptk::CXmlNode::copy | ( | const CXmlNode & | node | ) | [virtual] |
Performs a deep copy of node and all its subnodes.
| node | const CXmlNode&, a node to copy from |
| CXmlNode* sptk::CXmlNode::findFirst | ( | std::string | name, | |
| bool | recursively = true | |||
| ) | const |
Finds the first subnode with the given name.
Returns node pointer or NULL, if the node with such name is not found.
| name | std::string, the name to find | |
| recursively | bool, if true, also search in all subnodes |
| CXmlNode* sptk::CXmlNode::findOrCreate | ( | std::string | name, | |
| bool | recursively = true | |||
| ) |
Finds the first subnode with the given name, or creates a new one.
Returns node pointer. If the node with such name is not found, then new node is created.
| name | std::string, the name to find | |
| recursively | bool, if true, also search in all subnodes |
| virtual CXmlValue sptk::CXmlNode::getAttribute | ( | std::string | attr, | |
| const char * | defaultValue = "" | |||
| ) | const [inline, virtual] |
Returns attribute value for given attribute. HTML tags can have empty attributes, for those you should use has_attribute() method.
| attr | name of attribute | |
| defaultValue | const char *, a default value. If attribute doesn't exist then default value is returned. |
Reimplemented in sptk::CXmlElement.
| virtual bool sptk::CXmlNode::hasAttribute | ( | const char * | attr | ) | const [inline, virtual] |
Returns true, if given attribute is found
| attr | const char *, attribute to search |
Reimplemented in sptk::CXmlElement.
Inserts a subnode.
| pos | iterator, insert position with the list of subnodes | |
| node | CXmlNode*, node to insert |
Reimplemented in sptk::CXmlElement.
| virtual void sptk::CXmlNode::name | ( | const char * | name | ) | [pure virtual] |
Sets new name for node.
| name | const char *, new node name |
Implemented in sptk::CXmlDoc, sptk::CXmlNamedItem, sptk::CXmlBaseTextNode, and sptk::CXmlPI.
| virtual void sptk::CXmlNode::name | ( | const std::string & | name | ) | [pure virtual] |
Sets the new name for the node.
| name | const std::string&, new node name |
Implemented in sptk::CXmlDoc, sptk::CXmlNamedItem, sptk::CXmlBaseTextNode, and sptk::CXmlPI.
| virtual const std::string& sptk::CXmlNode::name | ( | ) | const [pure virtual] |
Returns the node name.
The meaning of the name depends on the node type:
Implemented in sptk::CXmlDoc, sptk::CXmlNamedItem, sptk::CXmlBaseTextNode, and sptk::CXmlPI.
| virtual bool sptk::CXmlNode::nameIs | ( | const std::string * | sstName | ) | const [inline, protected, virtual] |
Always returns false for CXmlNode since it has no name.
| sstName | const string*, SST name pointer to compare node name with |
Reimplemented in sptk::CXmlNamedItem.
| CXmlNode& sptk::CXmlNode::operator[] | ( | std::string | name | ) | [inline] |
Finds the first subnode with the given name, or creates a new one.
Returns node pointer. If the node with such name is not found, then new node is created. This is a shortcut for findOrCreate(name,false);
| name | std::string, the name to find |
| CXmlNode* sptk::CXmlNode::parent | ( | ) | const [inline] |
Returns parent node of this node.
For CXmlDocument this returns 'this' pointer.
| virtual void sptk::CXmlNode::remove | ( | CXmlNode * | node | ) | [inline, virtual] |
Removes a subnode.
Release all the allocated memory and disconnects from parent (this node)
Reimplemented in sptk::CXmlElement.
| virtual void sptk::CXmlNode::save | ( | CBuffer & | buffer, | |
| int | indent = 0 | |||
| ) | const [virtual] |
Saves node to buffer.
| buffer | to save | |
| indent | how many indent spaces at start |
Reimplemented in sptk::CRegistry, and sptk::CXmlDoc.
| void sptk::CXmlNode::select | ( | CXmlNodeVector & | nodes, | |
| std::string | xpath | |||
| ) |
Selects nodes as defined by XPath.
The implementation is just started, so only limited XPath standard part is supported. Currently, examples 1 through 6 from http://www.zvon.org/xxl/XPathTutorial/Output/example6.html are working fine with the exceptions:
| nodes | CXmlNodeVector&, the resulting list of subnodes | |
| xpath | std::string, the xpath for subnodes |
| virtual void sptk::CXmlNode::setAttribute | ( | const std::string & | attr, | |
| CXmlValue | value, | |||
| const char * | defaultValue = "" | |||
| ) | [inline, virtual] |
Sets new value to attribute 'attr'. If attribute is not found, it's added to map.
| attr | const string&, an attribute name | |
| value | CXmlValue, attribute value | |
| defaultValue | const char *, a default value. If attribute value is matching default value than attribute isn't stored (or removed if it existed). |
Reimplemented in sptk::CXmlElement.
| virtual void sptk::CXmlNode::setAttribute | ( | const char * | attr, | |
| CXmlValue | value, | |||
| const char * | defaultValue = "" | |||
| ) | [inline, virtual] |
Sets new value to attribute 'attr'. If attribute is not found, it's added to map.
| attr | attribute name | |
| value | attribute value | |
| defaultValue | const char *, a default value. If attribute value is matching default value than attribute isn't stored (or removed if it existed). |
Reimplemented in sptk::CXmlElement.
| void sptk::CXmlNode::text | ( | std::string | txt | ) |
Sets text for the node.
First, the node child nodes are removed. Then, new CXmlNodeText is added to this node.
| txt | std::string, node text |
| std::string sptk::CXmlNode::text | ( | ) | const |
Returns cdatas combined from children.
E.g. "Some <tag>text</tag> here" becomes: "Some text here"
| virtual void sptk::CXmlNode::unlink | ( | CXmlNode * | node | ) | [inline, virtual] |
| virtual void sptk::CXmlNode::value | ( | const char * | new_value | ) | [inline, virtual] |
Sets new value to node.
| new_value | const char *, value to set |
Reimplemented in sptk::CXmlAttribute, and sptk::CXmlBaseTextNode.
| virtual void sptk::CXmlNode::value | ( | const std::string & | new_value | ) | [inline, virtual] |
Sets new value to node.
| new_value | const std::string &, new value |
Reimplemented in sptk::CXmlAttribute, and sptk::CXmlBaseTextNode.
| virtual const std::string& sptk::CXmlNode::value | ( | ) | const [inline, virtual] |
Returns the value of the node.
The meaning of the value depends on the node type. DOM_DOCUMENT and DOM_ELEMENT don't have values
Reimplemented in sptk::CXmlAttribute, and sptk::CXmlBaseTextNode.