UI::GXML::Tree Class Reference

XML tree. More...

`#include <Tree.hpp>`

Inheritance diagram for UI::GXML::Tree:
Collaboration diagram for UI::GXML::Tree:

## Data Structures

class | Dump
| Serializer for Tree. More...
class | Node
| A XML node. More...
class | NodeSet
| Vector of nodes with specialised support. More...

## Public Types

enum | ErrorCode { Parse_ , Mem_ , NoNode_ , Internal_ }
| Error codes for exceptions.
typedef CodeException< ErrorCode > | Exception
| Exceptions for this class.
typedef std::map< std::string, std::string > | NamespaceMap
| Structure holding namespaces for xPath expressions.

## Public Member Functions

Tree & | operator= (Tree const &tree)
| Copy operator.
bool | operator== (Tree const &tree)
| Comparison.
Tree & | setTopLevelNamespaces ()
Tree & | setXPathNamespace (std::string const &prefix, std::string const &uri)
| Set custom xml namespace known in xPath queries.
std::string | dump (bool const &format=false, std::string const &encoding=DefaultEncoding_) const
| Tree dump shortcut.
std::string | formatDump (std::string const &encoding=DefaultEncoding_) const
| As dump, but will reparse the tree first.
std::string | getOrigEncoding () const
| Get original document's encoding.
void | setName (std::string const &xpath, std::string const &name)
| Set name of node(s).
void | unlink (std::string const &xpath)
| Remove node(s) from tree.
Tree configuration.
Tree & | setContext (bool on=true)
| (Un)configure the tree to use a fix xpath context.
XPathContext * | getContext () const
| Get fixed context.
Get objects from xpaths.
XPathObject | getXPathObject (std::string const &xpath) const
NodeSet | getNodeSet (std::string const &xpath) const
Node | getNode (std::string const &xpath, bool const &doThrow=true) const
Node | getRootNode () const
| Shortcut to get the root node.
Get number of nodes from xpath (or count > 0 for exists).
int | getCount (std::string const &xpath) const
bool | exists (std::string const &xpath, int const times=1) const
Set/get content of node(s) (i.e., of first child text node).
char const * | getContentC (std::string const &xpath) const
std::string | getContent (std::string const &xpath) const
void | setContent (std::string const &xpath, std::string const &content)
Set/get attributes of nodes.
void | setAttribute (std::string const &xpath, std::string const &name, std::string const &content)
std::string | getAttribute (std::string const &xpath, std::string const &name) const
Add a new (element) child node.
Node | addChild (std::string const &xpath, std::string const &name, std::string const &content="")
Node | addChild (std::string const &xpath, Node const &node)
Add an XML segment (serialized, or as tree).
void | addTree (std::string const &xpath, Tree const &source, std::string const &sourceXPath="/*")
void | addXML (std::string const &xpath, std::string const &source, std::string const &sourceXPath="/*")

## Static Public Attributes

static std::string const | DefaultEncoding_
| Default encoding. This is used for any dumps if not specified otherwise.
static std::string const | DefaultEncodings_
| Comma-separated uppercase list of the name and all allowed aliases the default encoding.
static std::string const | DefaultDocbase_
| Default document base. This is used for from-memory parsing if not specified otherwise.

## Protected Member Functions

| Tree ()
| Protected default constructor.
Tree & | setDontFreeDoc (bool on=true)
| En/disable freeing of underlying libxml2 doc_ tree. Use with caution.

## Protected Attributes

NamespaceMap | xPathNamespaces_
| Prefixs and URIs for custom xml namespaces in xPath queries.

## Friends

class | XSLTransTree
class | SchemaTree
class | RelaxNGTree
class | XMLTree
| Compat only.
class | XPathContext
| XPathContext needs access to libxml2 doc ptr.

## Standard tree constructors.

enum | FileConstructor { File_ }
| Helper enum for constructor from file name.
| Tree (char const *xml, int len=-1, std::string const &base=DefaultDocbase_, int const options=0)
| Construct from C string or buffer.
| Tree (std::string const &xml, std::string const &base=DefaultDocbase_, int const options=0)
| Construct from string.
| Tree (std::istream &xml, std::string const &base=DefaultDocbase_, int const options=0)
| Construct from istream.
| Tree (FileConstructor const &dummy, std::string const &file, int const options=0)
| Construct from file name.
| Tree (Tree const &tree)
| Construct from another Tree.

## Detailed Description

XML tree.

Examples
  UnitTests.cpp, and XSLTProc.cpp.

## Member Function Documentation

## dump()

std::string UI::GXML::Tree::dump | ( | bool const & | format = `false`,
|  | std::string const & | encoding = `DefaultEncoding_`
| ) |  | const

Tree dump shortcut.

See also
  Tree::Dump.

Examples
  UnitTests.cpp.

Referenced by formatDump(), and operator==().

## formatDump()

std::string UI::GXML::Tree::formatDump | ( | std::string const & | encoding = `DefaultEncoding_` | ) | const

As dump, but will reparse the tree first.

This may be useful to get formatting right if you modified the tree after the initial parsing.

References dump().

## getContext()

XPathContext * UI::GXML::Tree::getContext | ( |  | ) | const

Get fixed context.

Attention
  XPathContexts are not thread save.

## operator==()

bool UI::GXML::Tree::operator== | ( | Tree const & | tree | ) |

Comparison.

Note
  This does a string compare on dumps, so it's rather expensive.

References dump().

## setTopLevelNamespaces()

Tree & UI::GXML::Tree::setTopLevelNamespaces | ( |  | ) |

Todo:
  Learn about namespaces, and why this is still needed (namespace parse option?).

## Field Documentation

## DefaultEncodings_

std::string const UI::GXML::Tree::DefaultEncodings_

static

Comma-separated uppercase list of the name and all allowed aliases the default encoding.

Note
  "Allowed aliases" as supported by glibc's (2.3.2) iconv. According to IANA charset registry (2002-09-30), UTF-8 has no aliases.

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

- Tree.hpp
- Tree.cpp