summaryrefslogtreecommitdiff
path: root/src/xml.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/xml.cc')
-rw-r--r--src/xml.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/xml.cc b/src/xml.cc
new file mode 100644
index 00000000..3863bdff
--- /dev/null
+++ b/src/xml.cc
@@ -0,0 +1,34 @@
+#include "xml.h"
+
+XMLFile::XMLFile (string file, string root_id)
+{
+ xmlpp::DomParser parser;
+ parser.parse_file (file);
+ if (!parser) {
+ throw XMLError ("could not parse XML");
+ }
+
+ _root = parser.get_document()->get_root_node ();
+ if (_root->get_name() != root_id) {
+ throw XMLError ("unrecognised root node");
+ }
+}
+
+string
+XMLFile::string_tag (string id)
+{
+ stringstream x;
+ x << _root->get_name() << "/" << id;
+ xmlpp::NodeSet n = _root->find (x.str ());
+ if (n.empty ()) {
+ throw XMLError ("missing XML tag");
+ } else if (n.size() > 1) {
+ throw XMLError ("duplicate XML tag");
+ }
+
+ xml::Node::NodeList c = n.front()->get_children ();
+ if (c.empty()
+
+
+ return n.front()->get_name ();
+}