sptk2 logo
SPTK Home Page

sptk::CXmlNode Class Reference
[XML]

XML node. More...

#include <CXmlNode.h>

Inheritance diagram for sptk::CXmlNode:

sptk::CXmlBaseTextNode sptk::CXmlNamedItem sptk::CXmlCDataSection sptk::CXmlComment sptk::CXmlPI sptk::CXmlText sptk::CXmlAttribute sptk::CXmlElement sptk::CXmlDoc sptk::CRegistry

List of all members.

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

CXmlNodefindFirst (std::string name, bool recursively=true) const
 Finds the first subnode with the given name.
CXmlNodefindOrCreate (std::string name, bool recursively=true)
 Finds the first subnode with the given name, or creates a new one.
CXmlNodeoperator[] (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.
CXmlNodeparent () const
 Returns parent node of this node.
CXmlDocdocument () 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 CXmlAttributesattributes ()
 Returns referrence to node attributes.
virtual const CXmlAttributesattributes () 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

CXmlDocm_document
 Parent document pointer.
CXmlNodem_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


Detailed Description

XML node.

Basic class for any XML node


Member Enumeration Documentation

Node type enumeration.

Enumerator:
DOM_UNDEFINED  Type isn't defined yet.
DOM_DOCUMENT  Document node.
DOM_ELEMENT  Normal element node, can contain subnodes.
DOM_PI  Processing Instruction node.
DOM_TEXT  Cdata where all default entities MUST be escaped.
DOM_CDATA_SECTION  Cdata section, which can contain preformatted char data.
DOM_COMMENT  Comment node.
DOM_ATTRIBUTE  Attribute node.


Constructor & Destructor Documentation

sptk::CXmlNode::CXmlNode ( CXmlDoc doc  )  [inline, protected]

Protected constructor - for derived classes.

Parameters:
doc CXmlDoc&, node document

sptk::CXmlNode::CXmlNode ( CXmlNode parent  )  [inline, protected]

Protected constructor - for derived classes.

Parameters:
parent CXmlNode&, node document

References document(), and push_back().


Member Function Documentation

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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
attr name of attribute
defaultValue const char *, a default value. If attribute doesn't exist then default value is returned.
Returns:
attribute value

Reimplemented in sptk::CXmlElement.

virtual bool sptk::CXmlNode::hasAttribute ( const char *  attr  )  const [inline, virtual]

Returns true, if given attribute is found

Parameters:
attr const char *, attribute to search

Reimplemented in sptk::CXmlElement.

virtual void sptk::CXmlNode::insert ( iterator  pos,
CXmlNode node 
) [inline, virtual]

Inserts a subnode.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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);

Parameters:
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.

Parameters:
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:

  • no functions are supported yet.
    Parameters:
    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.

Parameters:
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.

Parameters:
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.

Parameters:
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]

Removes a subnode.

Disconnects subnode from parent (this node)

Reimplemented in sptk::CXmlElement.

virtual void sptk::CXmlNode::value ( const char *  new_value  )  [inline, virtual]

Sets new value to node.

Parameters:
new_value const char *, value to set
See also:
value()

Reimplemented in sptk::CXmlAttribute, and sptk::CXmlBaseTextNode.

virtual void sptk::CXmlNode::value ( const std::string &  new_value  )  [inline, virtual]

Sets new value to node.

Parameters:
new_value const std::string &, new value
See also:
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.


The documentation for this class was generated from the following file:

Mon Mar 5 11:56:22 2012: SPTK 3.5.7