#include <Xml.h>
Classes | |
| class | Attr |
| XML attribute. More... | |
| class | ConstIter |
| class | ExcAttrNotFound |
| Exception expressing the absence of an expected attribute. More... | |
| class | ExcChildNotFound |
| Exception expressing the absence of an expected child node. More... | |
| class | Exception |
| Base class for XmlTree exceptions. More... | |
| class | ExcUnknownNodeType |
| Exception implying an XML node of an unknown type. Implies a low-level problem communicating with RapidXML. More... | |
| class | Iter |
| An iterator over the children of an XmlTree. More... | |
| class | ParseOptions |
| Options for XML parsing. Passed to the XmlTree constructor. More... | |
Public Types | |
| enum | NodeType { NODE_UNKNOWN, NODE_DOCUMENT, NODE_ELEMENT, NODE_CDATA, NODE_COMMENT, NODE_DATA } |
| Enum listing all types of XML nodes understood by the parser. More... | |
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. | |
| NodeType | getNodeType () const |
| Returns the type of this node as a NodeType. | |
| void | setNodeType (NodeType type) |
| Sets the type of this node to NodeType type. | |
| bool | isDocument () const |
| Returns whether this node is a document node, meaning it is a root node. | |
| bool | isElement () const |
| Returns whether this node is an element node. | |
| bool | isCData () const |
| Returns whether this node represents CDATA. Only possible when a document's ParseOptions disabled collapsing CDATA. | |
| bool | isComment () 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. | |
| void | setTag (const std::string &tag) |
| Sets the tag or name of the node to the string tag. | |
| std::string | getValue () const |
| Returns the value of the node as a string. | |
| template<typename T > | |
| T | getValue () const |
| Returns the value of the node parsed as a T. Requires T to support the istream>> operator. | |
| template<typename T > | |
| T | getValue (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. | |
| void | setValue (const std::string &value) |
| Sets the value of the node to the string value. | |
| template<typename T > | |
| void | setValue (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. | |
| bool | hasParent () 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. | |
| Iter | find (const std::string &relativePath, bool caseSensitive=false, char separator= '/') |
| Returns the first child that matches relativePath or end() if none matches. | |
| ConstIter | find (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const |
| Returns the first child that matches relativePath or end() if none matches. | |
| bool | hasChild (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 | operator[] (const std::string &attrName) const |
| Returns an Attr accessor. If the attribute does not exists its Attr's value will be an empty string. | |
| Attr | operator[] (const std::string &attrName) |
| Returns an Attr accessor. If the attribute does not exists its Attr's value will be an empty string. Assigning the Attr is the equivalent of calling setAttribute( attrName ). | |
| 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. | |
| template<typename T > | |
| T | getAttributeValue (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" ); | |
| template<typename T > | |
| T | getAttributeValue (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) |
| template<typename T > | |
| XmlTree & | setAttribute (const std::string &attrName, const T &value) |
| bool | hasAttribute (const std::string &attrName) const |
| std::string | getPath (char separator= '/') const |
| Iter | begin () |
| Iter | begin (const std::string &filterPath, bool caseSensitive=false, char separator= '/') |
| ConstIter | begin () const |
| ConstIter | begin (const std::string &filterPath, bool caseSensitive=false, char separator= '/') const |
| Iter | end () |
| ConstIter | end () const |
| void | push_back (const XmlTree &newChild) |
| std::string | getDocType () const |
| void | setDocType (const std::string &docType) |
| void | write (DataTargetRef target, bool createDocument=true) |
| 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 | |
| static XmlTree | createDoc () |
| Returns an XML document node. | |
Friends | |
| std::ostream & | operator<< (std::ostream &out, const XmlTree &xml) |
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.
Default constructor, creating an empty node.
| cinder::XmlTree::XmlTree | ( | const XmlTree & | rhs | ) |
Copy constuctor.
| cinder::XmlTree::XmlTree | ( | DataSourceRef | dataSource, |
| ParseOptions | parseOptions = ParseOptions() |
||
| ) | [explicit] |
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" ) );
| cinder::XmlTree::XmlTree | ( | const std::string & | xmlString, |
| ParseOptions | parseOptions = ParseOptions() |
||
| ) | [explicit] |
Parses the XML contained in the string xmlString using the options parseOptions.
| cinder::XmlTree::XmlTree | ( | const std::string & | tag, |
| const std::string & | value, | ||
| XmlTree * | parent = 0, |
||
| NodeType | type = NODE_ELEMENT |
||
| ) | [explicit] |
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.
| static XmlTree cinder::XmlTree::createDoc | ( | ) | [static] |
Returns an XML document node.
| NodeType cinder::XmlTree::getNodeType | ( | ) | const |
Returns the type of this node as a NodeType.
| void cinder::XmlTree::setNodeType | ( | NodeType | type | ) |
Sets the type of this node to NodeType type.
| bool cinder::XmlTree::isDocument | ( | ) | const |
Returns whether this node is a document node, meaning it is a root node.
| bool cinder::XmlTree::isElement | ( | ) | const |
Returns whether this node is an element node.
| bool cinder::XmlTree::isCData | ( | ) | const |
Returns whether this node represents CDATA. Only possible when a document's ParseOptions disabled collapsing CDATA.
| bool cinder::XmlTree::isComment | ( | ) | const |
Returns whether this node represents a comment. Only possible when a document's ParseOptions enabled parsing commments.
| const std::string& cinder::XmlTree::getTag | ( | ) | const |
Returns the tag or name of the node as a string.
| void cinder::XmlTree::setTag | ( | const std::string & | tag | ) |
Sets the tag or name of the node to the string tag.
| std::string cinder::XmlTree::getValue | ( | ) | const |
Returns the value of the node as a string.
| T cinder::XmlTree::getValue | ( | ) | const |
Returns the value of the node parsed as a T. Requires T to support the istream>> operator.
| T cinder::XmlTree::getValue | ( | 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.
| void cinder::XmlTree::setValue | ( | const std::string & | value | ) |
Sets the value of the node to the string value.
| void cinder::XmlTree::setValue | ( | 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.
| bool cinder::XmlTree::hasParent | ( | ) | const |
Returns whether this node has a parent node.
Returns a reference to the node which is the parent of this node.
| const XmlTree& cinder::XmlTree::getParent | ( | ) | const |
Returns a reference to the node which is the parent of this node.
| Iter cinder::XmlTree::find | ( | const std::string & | relativePath, |
| bool | caseSensitive = false, |
||
| char | separator = '/' |
||
| ) |
Returns the first child that matches relativePath or end() if none matches.
| ConstIter cinder::XmlTree::find | ( | const std::string & | relativePath, |
| bool | caseSensitive = false, |
||
| char | separator = '/' |
||
| ) | const |
Returns the first child that matches relativePath or end() if none matches.
| bool cinder::XmlTree::hasChild | ( | const std::string & | relativePath, |
| bool | caseSensitive = false, |
||
| char | separator = '/' |
||
| ) | const |
Returns whether at least one child matches relativePath.
| XmlTree & cinder::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 & cinder::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& cinder::XmlTree::getChildren | ( | ) |
Returns a reference to the node's list of children nodes.
| const Container& cinder::XmlTree::getChildren | ( | ) | const |
Returns a reference to the node's list of children nodes.
| std::list<Attr>& cinder::XmlTree::getAttributes | ( | ) |
Returns a reference to the node's list of attributes.
| const std::list<Attr>& cinder::XmlTree::getAttributes | ( | ) | const |
Returns a reference to the node's list of attributes.
| const XmlTree::Attr & cinder::XmlTree::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 cinder::XmlTree::operator[] | ( | const std::string & | attrName | ) | const |
| Attr cinder::XmlTree::operator[] | ( | const std::string & | attrName | ) |
| const XmlTree& cinder::XmlTree::operator/ | ( | const std::string & | childName | ) | const |
Returns the first child that matches childName. Throws ExcChildNotFound if none matches.
| XmlTree& cinder::XmlTree::operator/ | ( | const std::string & | childName | ) |
Returns the first child that matches childName. Throws ExcChildNotFound if none matches.
| T cinder::XmlTree::getAttributeValue | ( | 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" );
| T cinder::XmlTree::getAttributeValue | ( | 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 & cinder::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& cinder::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.
| bool cinder::XmlTree::hasAttribute | ( | const std::string & | attrName | ) | const |
Returns whether the node has an attribute named attrName.
| string cinder::XmlTree::getPath | ( | char | separator = '/' | ) | const |
Returns a path to this node, separated by the character separator.
Returns an Iter to the first child node of this node.
| Iter cinder::XmlTree::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.
| ConstIter cinder::XmlTree::begin | ( | ) | const |
Returns an Iter to the first child node of this node.
| ConstIter cinder::XmlTree::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.
Returns an Iter which marks the end of the children of this node.
| ConstIter cinder::XmlTree::end | ( | ) | const |
Returns an Iter which marks the end of the children of this node.
| void cinder::XmlTree::push_back | ( | const XmlTree & | newChild | ) |
Appends a copy of the node newChild to the children of this node.
| std::string cinder::XmlTree::getDocType | ( | ) | const |
Returns the DOCTYPE string for this node. Only meaningful on a document's root node.
| void cinder::XmlTree::setDocType | ( | const std::string & | docType | ) |
Sets the DOCTYPE string for this node. Only meaningful on a document's root node.
| void cinder::XmlTree::write | ( | 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.
| shared_ptr< rapidxml::xml_document< char > > cinder::XmlTree::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.
| std::ostream& operator<< | ( | std::ostream & | out, |
| const XmlTree & | xml | ||
| ) | [friend] |
Streams the XmlTree xml to std::ostream out with standard formatting.