cpp-ElementTree
Python ElementTree-alike XML API for C++
Namespaces | Classes | Typedefs | Functions
etree Namespace Reference

ElementTree namespace; public classes and functions are defined here. More...

Namespaces

 feed
 RSS/ATOM feed parser implementation.
 
 html
 ElementTree HTML namespace; public classes and functions are defined here.
 

Classes

class  Attribute
 Proxy value type yielded by AttrIterator. More...
 
class  AttrIterator
 Represents iteration position produced by AttrMap::begin() and AttrMap::end(). More...
 
class  AttrMap
 Represents a mapping of an Element's attribute names to their values. More...
 
class  ChildIterator
 Represents iteration position produced by Element::begin() and Element::end(). More...
 
class  Element
 Represents a reference to a single XML element. More...
 
class  ElementTree
 Represents a reference to the root of an XML tree, the document itself. More...
 
class  Nullable
 Lightweight wrapper to add nullable semantics to another type. More...
 
class  QName
 Canonical representation for a name-namespace pair, without namespace prefix, in James Clark's Universal Names notation. More...
 
struct  xml_error
 Thrown to indicate libxml2 raised a parse error. More...
 
class  XPath
 Manages a compiled XPath expression. More...
 
class  XPathContext
 Manages a set of registered XPath namespaces and extension functions. More...
 

Typedefs

typedef std::vector< std::pair< std::string, std::string > > ns_list
 Represent a list of namespaces and their associated prefixes that should be defined while executing an XPath expression.
 
typedef Nullable< ElementNullableElement
 Convenient alias for Nullable<Element> to avoid typing "etree::" twice in scopes that do not import Nullable and Element.
 

Functions

Element fromstring (const char *s, size_t n=0)
 Parse an XML document from a character array and return a reference to its root node. More...
 
std::ostream & operator<< (std::ostream &out, const ElementTree &elem)
 Generate a human-readable description of an element tree. More...
 
std::ostream & operator<< (std::ostream &out, const Element &elem)
 Generate a human-readable description of an element. More...
 
std::ostream & operator<< (std::ostream &out, const QName &qname)
 Generate a human-readable description of a QName. More...
 
ElementTree parse (std::istream &is)
 Parse an XML document from a STL istream and return it. More...
 
ElementTree parse (const string &path)
 Parse an XML document from the filesystem and return it. More...
 
ElementTree parse (int fd)
 Parse an XML document from a file descriptor and return it. More...
 
Element SubElement (Element &parent, const QName &qname)
 Construct a new child element. More...
 
Element SubElement (Element &parent, const QName &qname, kv_list attribs)
 C++11: append a new child to an element and return it, taking the child's attributes from an initializer list. More...
 
string tostring (const Element &e)
 Serialize an element. More...
 
string tostring (const ElementTree &e)
 Serialize a tree. More...
 
template<typename Function >
void visit (Element elem, Function func)
 Depth-first visit an element and all of its subelements. More...
 

Detailed Description

ElementTree namespace; public classes and functions are defined here.

Function Documentation

Element etree::fromstring ( const char *  s,
size_t  n = 0 
)

Parse an XML document from a character array and return a reference to its root node.

Parameters
sXML document as a string.
nNumber of bytes to consume. If zero, assumes s is NUL-terminated.
Returns
Root Element.
std::ostream& etree::operator<< ( std::ostream &  out,
const ElementTree elem 
)

Generate a human-readable description of an element tree.

Parameters
outostream to write description to.
elemObject to describe.
Returns
ostream.
std::ostream& etree::operator<< ( std::ostream &  out,
const Element elem 
)

Generate a human-readable description of an element.

Parameters
outostream to write description to.
elemObject to describe.
Returns
ostream.
std::ostream& etree::operator<< ( std::ostream &  out,
const QName qname 
)

Generate a human-readable description of a QName.

Parameters
outostream to write description to.
qnameObject to describe.
Returns
ostream.
ElementTree etree::parse ( std::istream &  is)

Parse an XML document from a STL istream and return it.

Parameters
isInput stream.
Returns
ElementTree instance.
ElementTree etree::parse ( const string &  path)

Parse an XML document from the filesystem and return it.

Parameters
pathPath to file.
Returns
ElementTree instance.
ElementTree etree::parse ( int  fd)

Parse an XML document from a file descriptor and return it.

Parameters
fdFile descriptor number.
Returns
ElementTree instance.
Element etree::SubElement ( Element parent,
const QName qname 
)

Construct a new child element.

Parameters
parentParent element.
qnameNew element name.
Returns
New element.
Element etree::SubElement ( Element parent,
const QName qname,
kv_list  attribs 
)

C++11: append a new child to an element and return it, taking the child's attributes from an initializer list.

Parameters
parentParent element.
qnameNew element name.
attribsList of attribute name-value pairs from initialization list.
Returns
New element.
string etree::tostring ( const Element e)

Serialize an element.

Serialize an HTML element.

See ElementTree::tostring() for another variant.

Parameters
eElement to serialize.
Returns
UTF-8 encoded string.
string etree::tostring ( const ElementTree e)

Serialize a tree.

See ElementTree::tostring() for another variant.

Parameters
eElement to serialize.
Returns
UTF-8 encoded string.
template<typename Function >
void etree::visit ( Element  elem,
Function  func 
)

Depth-first visit an element and all of its subelements.

Parameters
elemElement to visit.
funcFunction called as (void)func(Element&);