The XmlTree class is designed to parse and XML documents and represent them hierarchically. An XmlTree node is composed of an optional value, attributes and a collection of children nodes, which are in turn XmlTree's.
Enums
Public Member Functions
-
XmlTree ()
Default constructor, creating an empty node.
-
XmlTree (const XmlTree &rhs)
Copy constuctor.
-
XmlTree &operator= (const XmlTree &rhs)
-
XmlTree (DataSourceRef dataSource, ParseOptions parseOptions=ParseOptions())
Parses XML contained in dataSource using the options parseOptions . Commonly used with the results of loadUrl() , loadFile() or loadResource() .
XmlTree myDoc( loadUrl( "http://rss.cnn.com/rss/cnn_topstories.rss" ) );
-
XmlTree (const std::string &xmlString, ParseOptions parseOptions=ParseOptions())
Parses the XML contained in the string xmlString using the options parseOptions .
-
XmlTree (const std::string &tag, const std::string &value, XmlTree *parent=0, NodeType type=NODE_ELEMENT)
Constructs an XML node with the tag tag , the value value . Optionally sets the pointer to the node's parent and sets the node type.
-
getNodeType () const
Returns the type of this node as a NodeType.
-
voidsetNodeType (NodeType type)
Sets the type of this node to NodeType type .
-
boolisDocument () const
Returns whether this node is a document node, meaning it is a root node.
-
boolisElement () const
Returns whether this node is an element node.
-
boolisCData () const
Returns whether this node represents CDATA. Only possible when a document's ParseOptions disabled collapsing CDATA.
-
boolisComment () const
Returns whether this node represents a comment. Only possible when a document's ParseOptions enabled parsing commments.
-
const std::string &getTag () const
Returns the tag or name of the node as a string.
-
voidsetTag (const std::string &tag)
Sets the tag or name of the node to the string tag .
-
std::stringgetValue () const
Returns the value of the node as a string.
-
TgetValue () const
Returns the value of the node parsed as a T. Requires T to support the istream>> operator.
-
TgetValue (const T &defaultValue) const
Returns the value of the node parsed as a T. If the value is empty or fails to parse defaultValue is returned. Requires T to support the istream>> operator.
-
voidsetValue (const std::string &value)
Sets the value of the node to the string value .
-
voidsetValue (const T &value)
Sets the value of the node to value which is converted to a string first. Requires T to support the ostream<< operator.
-
boolhasParent () const
Returns whether this node has a parent node.
-
XmlTree &getParent ()
Returns a reference to the node which is the parent of this node.
-
const XmlTree &getParent () const
Returns a reference to the node which is the parent of this node.
-
find (const std::string &relativePath, bool caseSensitive=false, char separator= '/')
Returns the first child that matches relativePath or end() if none matches.
-
find (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
Returns the first child that matches relativePath or end() if none matches.
-
boolhasChild (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
Returns whether at least one child matches relativePath .
-
XmlTree &getChild (const std::string &relativePath, bool caseSensitive=false, char separator= '/')
Returns the first child that matches relativePath . Throws ExcChildNotFound if none matches.
-
const XmlTree &getChild (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
Returns the first child that matches relativePath . Throws ExcChildNotFound if none matches.
-
Container &getChildren ()
Returns a reference to the node's list of children nodes.
-
const Container &getChildren () const
Returns a reference to the node's list of children nodes.
-
std::list< Attr > &getAttributes ()
Returns a reference to the node's list of attributes.
-
const std::list< Attr > &getAttributes () const
Returns a reference to the node's list of attributes.
-
const Attr &getAttribute (const std::string &attrName) const
Returns a reference to the node attribute named attrName . Throws AttrNotFoundExc if no attribute exists with that name.
-
const Attr
-
const XmlTree &operator/ (const std::string &childName) const
Returns the first child that matches childName . Throws ExcChildNotFound if none matches.
-
XmlTree &operator/ (const std::string &childName)
Returns the first child that matches childName . Throws ExcChildNotFound if none matches.
-
TgetAttributeValue (const std::string &attrName) const
Returns the value of the attribute attrName parsed as a T. Throws AttrNotFoundExc if no attribute exists with that name. Requires T to support the istream>> operator.
float size = myNode.getAttributeValue<float>( "size" );
-
TgetAttributeValue (const std::string &attrName, const T &defaultValue) const
Returns the value of the attribute attrName parsed as a T. Returns defaultValue if no attribute exists with that name or the attribute fails to cast to T. Requires T to support the istream>> operator.
float size = myNode.getAttributeValue<float>( "size", 1.0f );
-
XmlTree &setAttribute (const std::string &attrName, const std::string &value)
Sets the value of the attribute attrName to value . If the attribute does not exist it is appended.
-
XmlTree &setAttribute (const std::string &attrName, const T &value)
Sets the value of the attribute attrName to value , which is cast to a string first. Requires T to support the ostream<< operator. If the attribute does not exist it is appended.
-
boolhasAttribute (const std::string &attrName) const
Returns whether the node has an attribute named attrName .
-
std::stringgetPath (char separator= '/') const
Returns a path to this node, separated by the character separator .
-
begin ()
Returns an Iter to the first child node of this node.
-
begin (const std::string &filterPath, bool caseSensitive=false, char separator= '/')
Returns an Iter to the children node of this node which match the path filterPath .
-
begin () const
Returns an Iter to the first child node of this node.
-
begin (const std::string &filterPath, bool caseSensitive=false, char separator= '/') const
Returns an Iter to the children node of this node which match the path filterPath .
-
end ()
Returns an Iter which marks the end of the children of this node.
-
end () const
Returns an Iter which marks the end of the children of this node.
-
voidpush_back (const XmlTree &newChild)
Appends a copy of the node newChild to the children of this node.
-
std::stringgetDocType () const
Returns the DOCTYPE string for this node. Only meaningful on a document's root node.
-
voidsetDocType (const std::string &docType)
Sets the DOCTYPE string for this node. Only meaningful on a document's root node.
-
voidwrite (DataTargetRef target, bool createDocument=true)
Writes this XmlTree to target with standard formatting. If createDocument is true then an implicit parent NODE_DOCUMENT is created when necessary and this is treated as the root element.
-
std::shared_ptr< rapidxml::xml_document< char > >createRapidXmlDoc (bool createDocument=false) const
Returns a shared_ptr to a RapidXML xml_document. If createDocument is true then an implicit parent NODE_DOCUMENT is created when necessary and this is treated as the root element.
Static Public Member Functions
Friends
-
friend CI_API std::ostream &operator<< (std::ostream &out, const XmlTree &xml)
Streams the XmlTree xml to std::ostream out with standard formatting.