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);
363 XMLNodeList
XPathLookup(
const std::string& xpathExpr,
const NS& nsList);
369 bool SaveToFile(
const std::string& file_name)
const;
379 bool Validate(
const std::string &schema_file, std::string &err_msg);
385 std::ostream&
operator<<(std::ostream& out,
const XMLNode& node);
387 std::istream&
operator>>(std::istream& in, XMLNode& node);
393 std::vector<XMLNode*> nodes_;
409 void Add(
const std::list<XMLNode>&);
415 void AddNew(
const std::list<XMLNode>&);
417 int Size(
void)
const;
421 std::list<XMLNode>
Nodes(
void);