diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-30 22:03:25 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-30 22:03:25 +0100 |
| commit | 34a25d89b16a33b5f619ae0eaaa03c17f93980af (patch) | |
| tree | 9a1778042b027bbf71256f7ce855157d913fb6c1 /src/xml.cc | |
| parent | 25771018926d71d9312f216238d6a33a8892a748 (diff) | |
Hacks.
Diffstat (limited to 'src/xml.cc')
| -rw-r--r-- | src/xml.cc | 34 |
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 (); +} |
