summaryrefslogtreecommitdiff
path: root/src/utils/xml.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/xml.cpp')
-rw-r--r--src/utils/xml.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index e30450f0..98b474cb 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -22,9 +22,45 @@
*/
#include "xml.h"
+#include "../log.h"
+#include "../resources/resourcemanager.h"
namespace XML
{
+ Document::Document(const std::string &filename):
+ mDoc(NULL)
+ {
+ int size;
+ ResourceManager *resman = ResourceManager::getInstance();
+ char *data = (char*) resman->loadFile(filename.c_str(), size);
+
+ if (data) {
+ mDoc = xmlParseMemory(data, size);
+ free(data);
+
+ if (!mDoc)
+ logger->log("Error parsing XML file %s", filename.c_str());
+ } else {
+ logger->log("Error loading %s", filename.c_str());
+ }
+ }
+
+ Document::Document(const char *data, int size)
+ {
+ mDoc = xmlParseMemory(data, size);
+ }
+
+ Document::~Document()
+ {
+ if (mDoc)
+ xmlFreeDoc(mDoc);
+ }
+
+ xmlNodePtr Document::rootNode()
+ {
+ return mDoc ? xmlDocGetRootElement(mDoc) : 0;
+ }
+
int
getProperty(xmlNodePtr node, const char* name, int def)
{