1 #ifndef __BIAS_XMLIO_hh__
2 #define __BIAS_XMLIO_hh__
28 #include <bias_config.h>
31 #ifndef BIAS_HAVE_XML2
32 # error BIAS_HAVE_XML2 required to use XMLIO.hh. Please recompile BIAS with USE_XML2 or dont include this file.
38 typedef struct _xmlAttr xmlAttr;
39 typedef xmlAttr *xmlAttrPtr;
40 typedef struct _xmlNode xmlNode;
41 typedef xmlNode* xmlNodePtr;
42 typedef struct _xmlDoc xmlDoc;
43 typedef xmlDoc* xmlDocPtr;
46 #include <Base/Debug/Error.hh>
47 #include <Base/Debug/Debug.hh>
88 static int IsoLatin1ToUtf8(
const std::string& isoLatin1, std::string& utf8);
94 static int Utf8ToIsoLatin1(
const std::string& utf8, std::string& isoLatin1);
103 xmlNodePtr create(
const std::string& RootNodeName);
107 xmlNodePtr addChildNode(
const xmlNodePtr ParentNode,
108 const std::string& NewNodeName);
112 void addAttribute(
const xmlNodePtr Node,
113 const std::string& AttributeName,
114 bool AttributeValue);
117 void addAttribute(
const xmlNodePtr Node,
118 const std::string& AttributeName,
119 const std::string& AttributeValue);
122 void addAttribute(
const xmlNodePtr Node,
123 const std::string& AttributeName,
124 const char* AttributeValue);
128 void addAttribute(
const xmlNodePtr Node,
129 const std::string& AttributeName,
133 void addAttribute(
const xmlNodePtr Node,
134 const std::string& AttributeName,
135 double AttributeValue);
138 void addAttribute(
const xmlNodePtr Node,
139 const std::string& AttributeName,
140 const std::vector<double> &AttributeValue);
143 void addAttribute(
const xmlNodePtr Node,
144 const std::string& AttributeName,
145 const std::vector<int> &AttributeValue);
148 void addContent(
const xmlNodePtr Node,
const std::string& Content);
149 void addContent(
const xmlNodePtr Node,
const int Content);
150 void addContent(
const xmlNodePtr Node,
const double Content);
151 void addContent(
const xmlNodePtr Node,
const std::vector<int> Content);
155 void addComment(
const xmlNodePtr Node,
const std::string& Comment);
160 void setContent(
const xmlNodePtr Node,
const std::string& Content);
161 void setContent(
const xmlNodePtr Node,
const int Content);
162 void setContent(
const xmlNodePtr Node,
const double Content);
163 void setContent(
const xmlNodePtr Node,
const std::vector<int> Content);
169 int write(
const std::string& Filename,
170 bool AutoAddCompressionSuffix =
true)
const;
180 xmlNodePtr read(
const std::string& Filename);
184 xmlNodePtr getFirstChild(
const xmlNodePtr ParentNode);
190 xmlNodePtr getNextChild();
195 xmlNodePtr getNextChild(
const xmlNodePtr SiblingNode);
200 xmlNodePtr getChild(
const xmlNodePtr ParentNode,
201 const std::string& ChildName);
206 void GetChildren(
const xmlNodePtr ParentNode,
207 const std::string& ChildName,
208 std::vector<xmlNodePtr>& childrenWithSameName);
214 xmlNodePtr GetChildWithAttributeValueString(
const xmlNodePtr ParentNode,
215 const std::string& ChildName,
216 const std::string& AttributeName,
217 const std::string& AttributeValue);
221 std::string getNodeName(
const xmlNodePtr Node)
const;
225 void GetChildren(
const xmlNodePtr ParentNode,
226 std::vector<xmlNodePtr>& children);
230 std::string getNodeContentString(
const xmlNodePtr Node)
const;
231 int getNodeContentInt(
const xmlNodePtr Node)
const;
232 double getNodeContentDouble(
const xmlNodePtr Node)
const;
233 std::vector<int> getNodeContentVectorInt(
const xmlNodePtr Node)
const;
234 std::vector<double> getNodeContentVectorDouble(
const xmlNodePtr Node)
const;
239 xmlAttrPtr getFirstAttribute(
const xmlNodePtr Node);
245 xmlAttrPtr getNextAttribute();
249 void GetAttributes(
const xmlNodePtr Node,
250 std::vector<xmlAttrPtr>& attributes);
254 std::string getAttributeName(
const xmlAttrPtr Attribute)
const;
259 xmlAttrPtr getAttributeByName(
const xmlNodePtr Node,
260 const std::string& attribute_name);
266 bool getAttributeValueBool(
const xmlAttrPtr Attribute)
const;
267 std::string getAttributeValueString(
const xmlAttrPtr Attribute)
const;
268 int getAttributeValueInt(
const xmlAttrPtr Attribute)
const;
269 double getAttributeValueDouble(
const xmlAttrPtr Attribute)
const;
270 std::vector<double> getAttributeValueVecDbl(
const xmlAttrPtr Attribute)
const;
271 std::vector<int> getAttributeValueVecInt(
const xmlAttrPtr Attribute)
const;
277 bool getAttributeValueBool(
const xmlNodePtr Node,
278 const std::string& AttributeName)
const;
279 std::string getAttributeValueString(
const xmlNodePtr Node,
280 const std::string& AttributeName)
const;
281 int getAttributeValueInt(
const xmlNodePtr Node,
282 const std::string& AttributeName)
const;
283 double getAttributeValueDouble(
const xmlNodePtr Node,
284 const std::string& AttributeName)
const;
285 std::vector<double> getAttributeValueVecDbl(
const xmlNodePtr Node,
286 const std::string& AttributeName)
const;
287 std::vector<int> getAttributeValueVecInt(
const xmlNodePtr Node,
288 const std::string& AttributeName)
const;
294 int SetCompression(
int level=9);
299 int WriteToString(std::string &str);
304 xmlNodePtr ReadFromString(
const std::string &str);
309 Encoding_ = encoding;}
330 #endif // BIAS_HAVE_XML2
332 #endif // __BIAS_XMLIO_hh__
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
void SetEncoding(const std::string &encoding)
std::string IsoLatin1ToUtf8(const std::string &s)
std::string GetEncoding()