10 #ifndef UI_GXML_TREE_HPP 11 #define UI_GXML_TREE_HPP 30 class 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);
99 Tree(std::istream & 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);
279 int concat(
Node const & node,
280 bool const & format=
false, std::string
const & encoding=DefaultEncoding_);
284 bool const & format=
false, std::string
const & encoding=DefaultEncoding_);
287 int concat(
NodeSet const & nodeSet,
288 bool const & format=
false, std::string
const & encoding=DefaultEncoding_);
292 bool const & format=
false, std::string
const & encoding=DefaultEncoding_);
296 char const * getC()
const;
297 std::string
get()
const;
305 std::string
dump(
bool const & format=
false, std::string
const & encoding=DefaultEncoding_)
const;
313 Dump(
Tree const & tree,
bool const & format=
false, std::string
const & encoding=DefaultEncoding_);
317 char const * getC()
const;
318 std::string
get()
const;
327 std::string
dump(
bool const & format=
false, std::string
const & encoding=DefaultEncoding_)
const;
334 std::string
formatDump(std::string
const & encoding=DefaultEncoding_)
const;
338 XPathObject getXPathObject(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=
"");
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
394 XPathContextSwitch(
Tree const & tree, NamespaceMap
const & namespaces);
395 ~XPathContextSwitch();
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
Namespace for all Schlund+Partner Code.
Definition: Buffer.cpp:30
OutputBuffer holder class.
Definition: Buffer.hpp:52
Tree()
Protected default constructor.
Definition: Tree.cpp:74
bool operator==(Tree const &tree)
Comparison.
Definition: Tree.cpp:136
static std::string const DefaultEncoding_
Default encoding. This is used for any dumps if not specified otherwise.
Definition: Tree.hpp:65
void unlink()
Unlink this node (from underlying tree). Memory will be freed, and the node becomes a null node...
Definition: Tree.cpp:226
std::string getAttribute(std::string const &name) const
Like above, but return std::string.
Definition: Tree.cpp:323
XPathContext * getContext() const
Get fixed context.
Definition: Tree.cpp:158
ErrorCode
Error codes for exceptions.
Definition: Tree.hpp:51
std::string getXPath() const
Get associated XPath.
Definition: Tree.cpp:266
Node getParent() const
Definition: Tree.cpp:236
Tree & setContext(bool on=true)
(Un)configure the tree to use a fix xpath context.
Definition: Tree.cpp:141
Adding code facility to Exception.
Definition: Exception.hpp:34
FileConstructor
Helper enum for constructor from file name.
Definition: Tree.hpp:102
char const * hasAttribute(std::string const &name) const
Returns 0 if not found, else the attribute's content.
Definition: Tree.cpp:311
static std::string const DefaultDocbase_
Default document base. This is used for from-memory parsing if not specified otherwise.
Definition: Tree.hpp:74
XPath object holder class.
Definition: XPathObject.hpp:28
Node(xmlNode *const node=0)
Constructor from libxml2 node.
Definition: Tree.cpp:216
A XML node.
Definition: Tree.hpp:153
Node addSiblingAfter(std::string const &name, std::string const &content)
Add a new (element) sibling node.
Definition: Tree.cpp:387
static std::string const DefaultEncodings_
Comma-separated uppercase list of the name and all allowed aliases the default encoding.
Definition: Tree.hpp:72
NodeSet serializer.
Definition: Tree.hpp:269
Node addChild(std::string const &name, std::string const &content="")
Add a new (element) child node.
Definition: Tree.cpp:366
void setName(std::string const &name)
Definition: Tree.cpp:282
Node getRootNode() const
Shortcut to get the root node.
Definition: Tree.cpp:647
XML tree.
Definition: Tree.hpp:30
Vector of nodes with specialised support.
Definition: Tree.hpp:240
XPath context holder class.
Definition: XPathContext.hpp:34
Type getType() const
Get node type.
Definition: Tree.cpp:261
std::map< std::string, std::string > NamespaceMap
Structure holding namespaces for xPath expressions.
Definition: Tree.hpp:62
Serializer for Tree.
Definition: Tree.hpp:309
CodeException< ErrorCode > Exception
Exceptions for this class.
Definition: Tree.hpp:59
char const * getNameC() const
Definition: Tree.cpp:272
std::string dump(bool const &format=false, std::string const &encoding=DefaultEncoding_) const
Dump shortcut.
Definition: Tree.cpp:418
Tree & operator=(Tree const &tree)
Copy operator.
Definition: Tree.cpp:129
XML Schema Tree.
Definition: SchemaTree.hpp:26
std::string formatDump(std::string const &encoding=DefaultEncoding_) const
As dump, but will reparse the tree first.
Definition: Tree.cpp:616
bool isNull() const
Test if this is null ("not a tree node").
Definition: Tree.cpp:221
XSL translation result tree.
Definition: XSLTransTree.hpp:35
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
xmlElementType Type
Abstract from libxml2 type.
Definition: Tree.hpp:177
Tree & setDontFreeDoc(bool on=true)
En/disable freeing of underlying libxml2 doc_ tree. Use with caution.
Definition: Tree.cpp:204
NodeSet getChilds(std::string const &name="") const
Get all child nodes of this node.
Definition: Tree.cpp:256
Tree & setTopLevelNamespaces()
Definition: Tree.cpp:163
NodeSet getNodeSet(std::string const &xpath) const
Definition: Tree.cpp:337
std::string getOrigEncoding() const
Get original document's encoding.
Definition: Tree.cpp:621
friend class XMLTree
Compat only.
Definition: Tree.hpp:77
RelaxNG Schema XML Tree.
Definition: RelaxNGTree.hpp:26