3 #ifndef __ARC_XMLNODE_H__ 4 #define __ARC_XMLNODE_H__ 12 #include <libxml/xmlmemory.h> 13 #include <libxml/tree.h> 14 #include <libxml/parser.h> 15 #include <libxml/xpath.h> 16 #include <libxml/xpathInternals.h> 17 #include <libxml/xmlschemas.h> 29 :
public std::map<std::string, std::string> {
34 NS(
const char *prefix,
const char *uri) {
35 operator[](prefix) = uri;
40 NS(
const char *nslist[][2]) {
41 for (
int n = 0; nslist[n][0]; ++n)
42 operator[](nslist[n][0]) = nslist[n][1];
45 NS(
const std::map<std::string, std::string>& nslist)
46 : std::map<std::string, std::string>(nslist) {}
49 typedef std::list<XMLNode> XMLNodeList;
88 static void LogError(
void * ctx,
const char * msg, ...);
91 bool Validate(xmlSchemaPtr schema, std::string &err_msg);
111 XMLNode(
const std::string& xml);
114 XMLNode(
const char *xml,
int len = -1);
160 operator bool(
void)
const {
169 return ((node_ == node.node_) && (node_ != NULL));
173 return ((node_ != node.node_) || (node_ == NULL));
181 return ((
bool)(*
this) == val);
185 return ((
bool)(*
this) != val);
189 return ((std::string)(*
this) == str);
193 return ((std::string)(*
this) != str);
197 return ((std::string)(*
this) == str);
201 return ((std::string)(*
this) != str);
238 int Size(
void)
const;
244 std::string
Name(
void)
const;
246 std::string
Prefix(
void)
const;
257 void Prefix(
const std::string& prefix,
int recursion = 0);
261 void Name(
const char *name);
263 void Name(
const std::string& name) {
267 void GetXML(std::string& out_xml_str,
bool user_friendly =
false)
const;
272 void GetXML(std::string& out_xml_str,
const std::string& encoding,
bool user_friendly =
false)
const;
274 void GetDoc(std::string& out_xml_str,
bool user_friendly =
false)
const;
276 operator std::string(
void)
const;
284 void Set(
const std::string& content) {
319 void Namespaces(
const NS& namespaces,
bool keep =
false,
int recursion = -1);
328 XMLNode NewChild(
const char *name,
int n = -1,
bool global_order =
false);
331 return NewChild(name.c_str(), n, global_order);
335 XMLNode NewChild(
const char *name,
const NS& namespaces,
int n = -1,
bool global_order =
false);
337 XMLNode NewChild(
const std::string& name,
const NS& namespaces,
int n = -1,
bool global_order =
false) {
338 return NewChild(name.c_str(), namespaces, n, global_order);
356 XMLNodeList
Path(
const std::string& path);
367 XMLNodeList
XPathLookup(
const std::string& xpathExpr,
const NS& nsList);
373 bool SaveToFile(
const std::string& file_name)
const;
383 bool Validate(
const std::string &schema_file, std::string &err_msg);
389 std::ostream&
operator<<(std::ostream& out,
const XMLNode& node);
391 std::istream&
operator>>(std::istream& in, XMLNode& node);
397 std::vector<XMLNode*> nodes_;
413 void Add(
const std::list<XMLNode>&);
419 void AddNew(
const std::list<XMLNode>&);
421 int Size(
void)
const;
425 std::list<XMLNode>
Nodes(
void);
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
static void LogError(void *ctx, const char *msg,...)
void operator--(void)
Convenience operator to switch to previous element of same name.
Container for multiple XMLNode elements.
Definition: XMLNode.h:395
XMLNode GetRoot(void)
Get the root node from any child node of the tree.
void Replace(const XMLNode &node)
Makes a copy of supplied XML node and makes this instance refer to it.
void Destroy(void)
Destroys underlying XML element.
void StripNamespace(int recursion=0)
Removes namespace prefix from XML node(s).
int AttributesSize(void) const
Returns number of attributes of node.
Wrapper for LibXML library Tree interface.
Definition: XMLNode.h:61
Class to represent an XML namespace.
Definition: XMLNode.h:28
XMLNode Parent(void)
Get the parent node from any child node of the tree.
int Size(void) const
Returns number of children nodes.
bool operator==(const std::string &str)
This operator is needed to avoid ambiguity.
Definition: XMLNode.h:188
void New(XMLNode &node) const
Creates a copy of XML (sub)tree.
int Size(void) const
Return number of refered/stored nodes.
std::string FullName(void) const
Returns prefix:name of XML node.
Definition: XMLNode.h:248
bool operator==(const char *str)
This operator is needed to avoid ambiguity.
Definition: XMLNode.h:196
void operator++(void)
Convenience operator to switch to next element of same name.
bool MatchXMLName(const XMLNode &node1, const XMLNode &node2)
Returns true if underlying XML elements have same names.
NS(void)
Constructor creates empty namespace.
Definition: XMLNode.h:32
XMLNode Attribute(const std::string &name)
Returns XMLNode instance representing first attribute of node with specified by name.
Definition: XMLNode.h:298
XMLNode NewChild(const std::string &name, int n=-1, bool global_order=false)
Same as NewChild(const char*,int,bool).
Definition: XMLNode.h:330
bool operator!=(bool val)
This operator is needed to avoid ambiguity.
Definition: XMLNode.h:184
friend bool MatchXMLNamespace(const XMLNode &node1, const XMLNode &node2)
Returns true if underlying XML elements belong to same namespaces.
XMLNodeContainer(void)
Default constructor.
XMLNode NewChild(const std::string &name, const NS &namespaces, int n=-1, bool global_order=false)
Same as NewChild(const char*,const NS&,int,bool).
Definition: XMLNode.h:337
void Add(const XMLNode &)
Link XML subtree refered by node to container.
XMLNode Attribute(int n=0)
Returns XMLNode instance reresenting n-th attribute of node.
XMLNodeList Path(const std::string &path)
Collects nodes corresponding to specified path.
XMLNode Child(int n=0)
Returns XMLNode instance representing n-th child of XML element.
bool operator==(const XMLNode &node)
Returns true if 'node' represents same XML element.
Definition: XMLNode.h:168
bool ReadFromStream(std::istream &in)
Read XML document from stream and associate it with this node.
bool MatchXMLNamespace(const XMLNode &node1, const XMLNode &node2)
Returns true if underlying XML elements belong to same namespaces.
std::string Namespace(void) const
Returns namespace URI of XML node.
void Name(const std::string &name)
Assigns new name to XML node.
Definition: XMLNode.h:263
std::list< XMLNode > Nodes(void)
Returns all stored nodes.
bool operator==(bool val)
This operator is needed to avoid ambiguity.
Definition: XMLNode.h:180
bool SaveToFile(const std::string &file_name) const
Save string representation of node to file.
void Exchange(XMLNode &node)
Exchanges XML (sub)trees.
bool operator!(void) const
Returns true if instance does not point to XML element - invalid instance.
Definition: XMLNode.h:164
XMLNode NewChild(const char *name, int n=-1, bool global_order=false)
Creates new child XML element at specified position with specified name.
bool is_owner_
If true node is owned by this instance - hence released in destructor.
Definition: XMLNode.h:74
bool is_temporary_
This variable is reserved for future use.
Definition: XMLNode.h:76
XMLNode NewAttribute(const char *name)
Creates new attribute with specified name.
bool ReadFromFile(const std::string &file_name)
Read XML document from file and associate it with this node.
void GetXML(std::string &out_xml_str, bool user_friendly=false) const
Fills argument with this instance XML subtree textual representation.
std::ostream & operator<<(std::ostream &, const Period &)
Prints a Period-object to the given ostream – typically cout.
void Swap(XMLNode &node)
Swaps XML (sub)trees to which this and node refer.
bool Validate(xmlSchemaPtr schema, std::string &err_msg)
XMLNode(const XMLNode &node)
Copies existing instance.
Definition: XMLNode.h:105
std::string Name(void) const
Returns name of XML node.
bool operator!=(const XMLNode &node)
Returns false if 'node' represents same XML element.
Definition: XMLNode.h:172
bool SaveToStream(std::ostream &out) const
Save string representation of node to stream.
void Move(XMLNode &node)
Moves content of this XML (sub)tree to node.
void GetDoc(std::string &out_xml_str, bool user_friendly=false) const
Fills out_xml_str with whole XML document textual representation.
XMLNode operator[](int)
Returns n-th node in a store.
XMLNode(void)
Constructor of invalid node.
Definition: XMLNode.h:97
XMLNode Get(const std::string &name) const
Same as operator[]().
Definition: XMLNode.h:240
bool operator!=(const std::string &str)
This operator is needed to avoid ambiguity.
Definition: XMLNode.h:192
std::string Prefix(void) const
Returns namespace prefix of XML node.
~XMLNode(void)
Destructor.
XMLNode operator[](const char *name) const
Returns XMLNode instance representing first child element with specified name.
friend bool MatchXMLName(const XMLNode &node1, const XMLNode &node2)
Returns true if underlying XML elements have same names.
XMLNode operator[](const std::string &name) const
Returns XMLNode instance representing first child element with specified name.
Definition: XMLNode.h:218
XMLNodeContainer & operator=(const XMLNodeContainer &)
Same as copy constructor with current nodes being deleted first.
NS Namespaces(void)
Returns namespaces known at this node.
std::istream & operator>>(std::istream &in, XMLNode &node)
Read into XMLNode from input stream.
XMLNodeList XPathLookup(const std::string &xpathExpr, const NS &nsList)
Uses XPath to look up XML tree.
XMLNode & operator=(const char *content)
Sets textual content of node. All existing children nodes are discarded.
XMLNode(xmlNodePtr node)
Protected constructor for inherited classes.
Definition: XMLNode.h:82
void Set(const std::string &content)
Same as operator=. Used for bindings.
Definition: XMLNode.h:284
XMLNode & operator=(const std::string &content)
Sets textual content of node. All existing children nodes are discarded.
Definition: XMLNode.h:280
bool Same(const XMLNode &node)
Returns true if 'node' represents same XML element - for bindings.
Definition: XMLNode.h:176
XMLNode NewAttribute(const std::string &name)
Creates new attribute with specified name.
Definition: XMLNode.h:304
std::string NamespacePrefix(const char *urn)
Returns prefix of specified namespace or empty string if no such namespace.
NS(const char *prefix, const char *uri)
Constructor creates namespace with one entry.
Definition: XMLNode.h:34
void AddNew(const XMLNode &)
Copy XML subtree referenced by node to container.
NS(const char *nslist[][2])
Constructor creates namespace with multiple entries.
Definition: XMLNode.h:40
NS(const std::map< std::string, std::string > &nslist)
Constructor creates namespace with multiple entries.
Definition: XMLNode.h:45
bool operator!=(const char *str)
This operator is needed to avoid ambiguity.
Definition: XMLNode.h:200