summaryrefslogtreecommitdiff
path: root/project2/xmlScriptParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlScriptParser.cpp')
-rw-r--r--project2/xmlScriptParser.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/project2/xmlScriptParser.cpp b/project2/xmlScriptParser.cpp
new file mode 100644
index 0000000..8db4049
--- /dev/null
+++ b/project2/xmlScriptParser.cpp
@@ -0,0 +1,40 @@
+#include "xmlScriptParser.h"
+#include <libxml/xinclude.h>
+#include <boost/filesystem/convenience.hpp>
+
+XmlScriptParser::XmlScriptParser(const std::string & group, const std::string & name, bool ii) :
+ IsInclusion(ii)
+{
+ loadDocument(group + "/" + name + ".xml");
+}
+
+XmlScriptParser::XmlScriptParser(const std::string & file, bool ii) :
+ IsInclusion(ii)
+{
+ loadDocument(file);
+}
+
+void
+XmlScriptParser::loadDocument(const std::string & file)
+{
+ if (!boost::filesystem::exists(file)) {
+ if (IsInclusion) {
+ throw DependencyNotFound(file);
+ }
+ else {
+ throw NotFound(file);
+ }
+ }
+ try {
+ parse_file(file);
+ }
+ catch (const xmlpp::internal_error &) {
+ throw NotReadable(file);
+ }
+ for (int x; (x = xmlXIncludeProcessFlags(get_document()->cobj(), XML_PARSE_NOXINCNODE)); ) {
+ if (x < 0) {
+ throw IncludesError(file);
+ }
+ }
+}
+