#include <cxmlelement.h>
XML-typed NED parameters are accessible as cXMLElement via the cPar::xmlValue() method.
cXMLElement provides read only access to the XML, with functionality that resembles DOM. (A full-featured DOM implementation would have been too bloated for the purpose of accessing readonly configuration files).
Features: only readonly (getter) methods; represents only elements and text (entities, processing instructions, comments are ignored); attributes are presented as part of an element node (not as separate attribute nodes as in DOM); mixed content model not supported (element body cannot mix text with further elements); text is represented as a property of its enclosing element (and not as separate node as in DOM); CDATA sections are also represented as text (with the above restrictions); strings are presented in UTF-8 format (which is normal ASCII string if only characters 0x01-0x7F are used; encoding of the XML file itself may use arbitrary encoding provided it's supported by the underlying XML parser); no namespace support.
Supports XPath-like addressing via the getElementByPath() member function.
File inclusion via limited support of the XInclude 1.0 spec. An element <xi:include href="doc.xml"/> gets replaced with the content of the corresponding document. The "href" and "parse" attributes from the XInclude spec are supported.
Public Member Functions | |
Common properties | |
virtual const char * | getTagName () const |
virtual const char * | getSourceLocation () const |
virtual const char * | getNodeValue () const |
virtual const char * | getAttribute (const char *attr) const |
virtual bool | hasAttributes () const |
virtual const cXMLAttributeMap & | getAttributes () const |
Generic access to children and siblings | |
virtual cXMLElement * | getParentNode () const |
virtual bool | hasChildren () const |
virtual cXMLElement * | getFirstChild () const |
virtual cXMLElement * | getLastChild () const |
virtual cXMLElement * | getNextSibling () const |
virtual cXMLElement * | getPreviousSibling () const |
virtual cXMLElement * | getFirstChildWithTag (const char *tagname) const |
virtual cXMLElement * | getNextSiblingWithTag (const char *tagname) const |
virtual cXMLElementList | getChildren () const |
virtual cXMLElementList | getChildrenByTagName (const char *tagname) const |
virtual cXMLElementList | getElementsByTagName (const char *tagname) const |
Utility functions | |
cXMLElement * | getFirstChildWithAttribute (const char *tagname, const char *attr, const char *attrvalue=NULL) const |
cXMLElement * | getElementById (const char *idattrvalue) const |
cXMLElement * | getElementByPath (const char *pathexpression, cXMLElement *root=NULL, ParamResolver *resolver=NULL) const |
void | debugDump (int depth=0) const |
Classes | |
class | ParamResolver |
Base class for classes that resolve parameters ($PARAM) that occur in in XPath expressions to their values. More... |
|
Dumps tree content to ev in a XML-like format. This method is only useful for debugging, because it does not perform necessary escaping in text nodes and attribute values, so the output is not necessarily well-formed XML. |
|
Returns the value of the attribute with the given name. It returns NULL if the given attribute is not found. |
|
Returns attributes as a const (immutable) std::map.
|
|
Returns list of child elements.
|
|
Returns list of child elements with the given tag name.
|
|
Returns the first element which has an "id" attribute with the given value. ("id" attributes are supposed to be unique in an XML document.) Returns NULL if not found. |
|
Returns the first element designated by the given path expression. ("First" in the sense of preorder depth-first traversal.) Path expressions must be given in an XPath-like notation: they consist of path components (or "steps") separated by "/" or "//". A path component can be an element tag name, "*", "." or ".."; tag name and "*" can have an optional predicate in the form "[position]" or "[@attribute='value']". "/" means child element; "//" means a element any levels under the current one; ".", ".." and "*" mean what you expect them to: current element, parent element, element with any tag name. Examples:
The method throws an exception if the path expression is invalid, and returns NULL if the element is not found. |
|
Returns list of contained elements with the given tag name, in preorder traversal order.
|
|
Returns pointer to the first child element, or NULL if this element has no children.
|
|
Returns find first child element with the given tagname and the given attribute present, and (optionally) having the given value. tagname might be NULL -- then any element with the given attribute will be accepted. Returns NULL if not found. |
|
Returns pointer to the first child element with the given tag name, or NULL if this element has no such children.
|
|
Returns pointer to the last child element, or NULL if this element has no children.
|
|
Returns pointer to the next sibling of this element (i.e. the next child in the parent element). Returns NULL if there're no subsequent elements. getFirstChild() and getNextSibling() can be used to loop through the child list:
for (cXMLElement *child=node->getFirstChild(); child; child = child->getNextSibling()) { ... } |
|
Returns pointer to the next sibling of this element with the given tag name. Return NULL if there're no such subsequent elements. getFirstChildWithTag() and getNextSiblingWithTag() are a convient way to loop through elements with a certain tag name in the child list:
for (cXMLElement *child=node->getFirstChildWithTag("foo"); child; child = child->getNextSiblingWithTag("foo")) { ... } |
|
Returns text node in the element, or NULL otherwise. (Mixing text and child elements is not supported.) |
|
Returns the parent element, or NULL if this element has no parent.
|
|
Returns pointer to the previous sibling of this element (i.e. the previous child in the parent element). Returns NULL if there're no elements before this one. |
|
Returns a string containing a file/line position showing where this element originally came from.
|
|
Returns the element name.
|
|
Returns true if the node has attributes.
|
|
Returns true if the node has children.
|