10#ifndef UI_GXML_TREE_HPP
11#define UI_GXML_TREE_HPP
30class Tree:
private UI::Util::auto_base<xmlDoc>
45 static xmlDoc * create(
char const * xml,
int len, std::string
const & base,
int const options);
46 static xmlDoc * create(xmlDoc
const *
const doc);
47 static xmlDoc * create(std::string
const & file,
int const options);
93 Tree(
char const * xml,
int len=-1, std::string
const & base=
DefaultDocbase_,
int const options=0);
96 Tree(std::string
const & xml, std::string
const & base=
DefaultDocbase_,
int const options=0);
153 class Node:
private UI::Util::auto_base<xmlNode>
158 Node(xmlNode *
const node=0);
168 Node getChild()
const;
169 Node getNext()
const;
170 Node getPrev()
const;
189 std::string getName()
const;
190 void setName(std::string
const & name);
195 char const * getContentC()
const;
196 std::string getContent()
const;
197 void setContent(std::string
const & content);
201 char const *
hasAttribute(std::string
const & name)
const;
205 std::string
getAttribute(std::string
const & name)
const;
206 void setAttribute(std::string
const & name, std::string
const & content);
211 Node getNode(std::string
const & xpath,
bool const & doThrow=
true)
const;
219 Node addChild(std::string
const & name, std::string
const & content=
"");
229 std::string
dump(
bool const & format=
false, std::string
const & encoding=
DefaultEncoding_)
const;
232 using UI::Util::auto_base<xmlNode>::get;
233 using UI::Util::auto_base<xmlNode>::operator->;
236 static xmlNode *
const NullNode_;
249 NodeSet(
Node const & node=
Node(0),
bool const & childs=
false, std::string
const & name=
"");
250 NodeSet(
NodeSet const & ns,
bool const & childs=
false, std::string
const & name=
"");
251 void add(
Node const & node,
bool const & childs=
false, std::string
const & name=
"");
252 void add(
NodeSet const & ns,
bool const & childs=
false, std::string
const & name=
"");
266 std::string
getContent(std::string
const & nodeSeparator=
"")
const;
276 int concat(std::string
const & text);
296 char const * getC()
const;
297 std::string get()
const;
305 std::string
dump(
bool const & format=
false, std::string
const & encoding=
DefaultEncoding_)
const;
317 char const * getC()
const;
318 std::string get()
const;
327 std::string
dump(
bool const & format=
false, std::string
const & encoding=
DefaultEncoding_)
const;
338 XPathObject getXPathObject(std::string
const & xpath)
const;
339 NodeSet getNodeSet(std::string
const & xpath)
const;
340 Node getNode(std::string
const & xpath,
bool const & doThrow=
true)
const;
350 int getCount(std::string
const & xpath)
const;
351 bool exists(std::string
const & xpath,
int const times=1)
const;
356 char const * getContentC(std::string
const & xpath)
const;
357 std::string getContent(std::string
const & xpath)
const;
358 void setContent(std::string
const & xpath, std::string
const & content);
362 void setName(std::string
const & xpath, std::string
const & name);
366 void setAttribute(std::string
const & xpath, std::string
const & name, std::string
const & content);
367 std::string getAttribute(std::string
const & xpath, std::string
const & name)
const;
372 Node addChild(std::string
const & xpath, std::string
const & name, std::string
const & content=
"");
373 Node addChild(std::string
const & xpath,
Node const & node);
377 void unlink(std::string
const & xpath);
381 void addTree(std::string
const & xpath,
Tree const & source, std::string
const & sourceXPath=
"/*");
382 void addXML(std::string
const & xpath, std::string
const & source, std::string
const & sourceXPath=
"/*");
386 using UI::Util::auto_base<xmlDoc>::get;
387 using UI::Util::auto_base<xmlDoc>::operator->;
391 class XPathContextSwitch
395 ~XPathContextSwitch();
Adding code facility to Exception.
Definition Exception.hpp:35
OutputBuffer holder class.
Definition Buffer.hpp:53
RelaxNG Schema XML Tree.
Definition RelaxNGTree.hpp:27
XML Schema Tree.
Definition SchemaTree.hpp:27
Serializer for Tree.
Definition Tree.hpp:310
NodeSet serializer.
Definition Tree.hpp:270
int concat(std::string const &text)
Append a free text to the dump.
Definition Tree.cpp:520
Dump()
Default constructor, creates an empty dump.
Definition Tree.cpp:516
Vector of nodes with specialised support.
Definition Tree.hpp:241
std::string dump(bool const &format=false, std::string const &encoding=DefaultEncoding_) const
Dump shortcut.
Definition Tree.cpp:572
void unlink()
Unlink all nodes.
Definition Tree.cpp:489
std::string getContent(std::string const &nodeSeparator="") const
Get nodeset content.
Definition Tree.cpp:502
NodeSet getChilds(std::string const &name="") const
Get a nodeset with all childs of this set.
Definition Tree.cpp:497
A XML node.
Definition Tree.hpp:154
std::string getXPath() const
Get associated XPath.
Definition Tree.cpp:266
Node addChild(std::string const &name, std::string const &content="")
Add a new (element) child node.
Definition Tree.cpp:366
char const * getNameC() const
Definition Tree.cpp:272
Type getType() const
Get node type.
Definition Tree.cpp:261
void setName(std::string const &name)
Definition Tree.cpp:282
std::string getAttribute(std::string const &name) const
Like above, but return std::string.
Definition Tree.cpp:323
Node addSiblingAfter(std::string const &name, std::string const &content)
Add a new (element) sibling node.
Definition Tree.cpp:387
xmlElementType Type
Abstract from libxml2 type.
Definition Tree.hpp:177
NodeSet getChilds(std::string const &name="") const
Get all child nodes of this node.
Definition Tree.cpp:256
std::string dump(bool const &format=false, std::string const &encoding=DefaultEncoding_) const
Dump shortcut.
Definition Tree.cpp:418
NodeSet getNodeSet(std::string const &xpath) const
Definition Tree.cpp:337
bool isNull() const
Test if this is null ("not a tree node").
Definition Tree.cpp:221
Node getParent() const
Definition Tree.cpp:236
char const * hasAttribute(std::string const &name) const
Returns 0 if not found, else the attribute's content.
Definition Tree.cpp:311
void unlink()
Unlink this node (from underlying tree). Memory will be freed, and the node becomes a null node.
Definition Tree.cpp:226
char const * getAttributeC(std::string const &name) const
Like above, but always return valid c string (length 0 if not found).
Definition Tree.cpp:317
XML tree.
Definition Tree.hpp:31
std::map< std::string, std::string > NamespaceMap
Structure holding namespaces for xPath expressions.
Definition Tree.hpp:62
FileConstructor
Helper enum for constructor from file name.
Definition Tree.hpp:103
static std::string const DefaultDocbase_
Default document base. This is used for from-memory parsing if not specified otherwise.
Definition Tree.hpp:74
static std::string const DefaultEncodings_
Comma-separated uppercase list of the name and all allowed aliases the default encoding.
Definition Tree.hpp:72
ErrorCode
Error codes for exceptions.
Definition Tree.hpp:52
Tree & setDontFreeDoc(bool on=true)
En/disable freeing of underlying libxml2 doc_ tree. Use with caution.
Definition Tree.cpp:204
bool operator==(Tree const &tree)
Comparison.
Definition Tree.cpp:136
NamespaceMap xPathNamespaces_
Prefixs and URIs for custom xml namespaces in xPath queries.
Definition Tree.hpp:84
Tree & setXPathNamespace(std::string const &prefix, std::string const &uri)
Set custom xml namespace known in xPath queries.
Definition Tree.cpp:187
std::string dump(bool const &format=false, std::string const &encoding=DefaultEncoding_) const
Tree dump shortcut.
Definition Tree.cpp:611
void unlink(std::string const &xpath)
Remove node(s) from tree.
Definition Tree.cpp:698
Tree & setTopLevelNamespaces()
Definition Tree.cpp:163
std::string getOrigEncoding() const
Get original document's encoding.
Definition Tree.cpp:621
Tree & operator=(Tree const &tree)
Copy operator.
Definition Tree.cpp:129
Tree & setContext(bool on=true)
(Un)configure the tree to use a fix xpath context.
Definition Tree.cpp:141
Tree()
Protected default constructor.
Definition Tree.cpp:74
CodeException< ErrorCode > Exception
Exceptions for this class.
Definition Tree.hpp:59
std::string formatDump(std::string const &encoding=DefaultEncoding_) const
As dump, but will reparse the tree first.
Definition Tree.cpp:616
friend class XMLTree
Compat only.
Definition Tree.hpp:77
void setName(std::string const &xpath, std::string const &name)
Set name of node(s).
Definition Tree.cpp:673
XPathContext * getContext() const
Get fixed context.
Definition Tree.cpp:158
Node getRootNode() const
Shortcut to get the root node.
Definition Tree.cpp:647
static std::string const DefaultEncoding_
Default encoding. This is used for any dumps if not specified otherwise.
Definition Tree.hpp:65
XPath context holder class.
Definition XPathContext.hpp:35
XPath object holder class.
Definition XPathObject.hpp:29
XSL translation result tree.
Definition XSLTransTree.hpp:36
Namespace for all Schlund+Partner Code.
Definition Buffer.cpp:30