Cinder  0.9.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
cinder::XmlTree Class Reference

#include <Xml.h>

Classes

class  Attr
 
class  ConstIter
 
class  ExcAttrNotFound
 
class  ExcChildNotFound
 
class  Exception
 
class  ExcUnknownNodeType
 
class  Iter
 
class  ParseOptions
 

Public Types

enum  NodeType {
  NODE_UNKNOWN, NODE_DOCUMENT, NODE_ELEMENT, NODE_CDATA,
  NODE_COMMENT, NODE_DATA
}
 

Public Member Functions

 XmlTree ()
 
 XmlTree (const XmlTree &rhs)
 
XmlTreeoperator= (const XmlTree &rhs)
 
 XmlTree (DataSourceRef dataSource, ParseOptions parseOptions=ParseOptions())
 
 XmlTree (const std::string &xmlString, ParseOptions parseOptions=ParseOptions())
 
 XmlTree (const std::string &tag, const std::string &value, XmlTree *parent=0, NodeType type=NODE_ELEMENT)
 
NodeType getNodeType () const
 
void setNodeType (NodeType type)
 
bool isDocument () const
 
bool isElement () const
 
bool isCData () const
 
bool isComment () const
 
const std::string & getTag () const
 
void setTag (const std::string &tag)
 
std::string getValue () const
 
template<typename T >
getValue () const
 
template<typename T >
getValue (const T &defaultValue) const
 
void setValue (const std::string &value)
 
template<typename T >
void setValue (const T &value)
 
bool hasParent () const
 
XmlTreegetParent ()
 
const XmlTreegetParent () const
 
Iter find (const std::string &relativePath, bool caseSensitive=false, char separator= '/')
 
ConstIter find (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
 
bool hasChild (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
 
XmlTreegetChild (const std::string &relativePath, bool caseSensitive=false, char separator= '/')
 
const XmlTreegetChild (const std::string &relativePath, bool caseSensitive=false, char separator= '/') const
 
Container & getChildren ()
 
const Container & getChildren () const
 
std::list< Attr > & getAttributes ()
 
const std::list< Attr > & getAttributes () const
 
const AttrgetAttribute (const std::string &attrName) const
 
const Attr operator[] (const std::string &attrName) const
 
Attr operator[] (const std::string &attrName)
 
const XmlTreeoperator/ (const std::string &childName) const
 
XmlTreeoperator/ (const std::string &childName)
 
template<typename T >
getAttributeValue (const std::string &attrName) const
 
template<typename T >
getAttributeValue (const std::string &attrName, const T &defaultValue) const
 
XmlTreesetAttribute (const std::string &attrName, const std::string &value)
 
template<typename T >
XmlTreesetAttribute (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
 

Static Public Member Functions

static XmlTree createDoc ()
 

Friends

std::ostream & operator<< (std::ostream &out, const XmlTree &xml)
 

Member Enumeration Documentation

Enum listing all types of XML nodes understood by the parser.

Enumerator
NODE_UNKNOWN 
NODE_DOCUMENT 
NODE_ELEMENT 
NODE_CDATA 
NODE_COMMENT 
NODE_DATA 

Constructor & Destructor Documentation

cinder::XmlTree::XmlTree ( )

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.

Member Function Documentation

XmlTree & cinder::XmlTree::operator= ( const XmlTree rhs)
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.

template<typename T >
T cinder::XmlTree::getValue ( ) const

Returns the value of the node parsed as a T. Requires T to support the istream>> operator.

template<typename T >
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.

template<typename T >
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.

XmlTree& cinder::XmlTree::getParent ( )

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

Returns an Attr accessor. If the attribute does not exists its Attr's value will be an empty string.

Attr cinder::XmlTree::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& 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.

template<typename T >
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" );

template<typename T >
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.

template<typename T >
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.

Iter cinder::XmlTree::begin ( )

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.

Iter cinder::XmlTree::end ( )

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.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const XmlTree xml 
)
friend

Streams the XmlTree xml to std::ostream out with standard formatting.


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