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.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index 10436067f..420915d8f 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -2,7 +2,7 @@
* The ManaPlus Client
* Copyright (C) 2004-2009 The Mana World Development Team
* Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -32,6 +32,11 @@
#include "debug.h"
+static void xmlNullLogger(void *ctx A_UNUSED, const char *msg A_UNUSED, ...)
+{
+ // Does nothing, that's the whole point of it
+}
+
namespace XML
{
Document::Document(const std::string &filename, bool useResman):
@@ -96,12 +101,12 @@ namespace XML
xmlFreeDoc(mDoc);
}
- xmlNodePtr Document::rootNode()
+ XmlNodePtr Document::rootNode()
{
return mDoc ? xmlDocGetRootElement(mDoc) : nullptr;
}
- int getProperty(xmlNodePtr node, const char* name, int def)
+ int getProperty(XmlNodePtr node, const char* name, int def)
{
int &ret = def;
@@ -115,7 +120,7 @@ namespace XML
return ret;
}
- double getFloatProperty(xmlNodePtr node, const char* name, double def)
+ double getFloatProperty(XmlNodePtr node, const char* name, double def)
{
double &ret = def;
@@ -129,7 +134,7 @@ namespace XML
return ret;
}
- std::string getProperty(xmlNodePtr node, const char *name,
+ std::string getProperty(XmlNodePtr node, const char *name,
const std::string &def)
{
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
@@ -143,7 +148,7 @@ namespace XML
return def;
}
- bool getBoolProperty(xmlNodePtr node, const char* name, bool def)
+ bool getBoolProperty(XmlNodePtr node, const char* name, bool def)
{
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
@@ -154,15 +159,32 @@ namespace XML
return def;
}
- xmlNodePtr findFirstChildByName(xmlNodePtr parent, const char *name)
+ XmlNodePtr findFirstChildByName(XmlNodePtr parent, const char *name)
{
for_each_xml_child_node(child, parent)
{
- if (xmlStrEqual(child->name, BAD_CAST name))
+ if (xmlNameEqual(child, name))
return child;
}
return nullptr;
}
+ // Initialize libxml2 and check for potential ABI mismatches between
+ // compiled version and the shared library actually used.
+ void initXML()
+ {
+ xmlInitParser();
+ LIBXML_TEST_VERSION;
+
+ // Suppress libxml2 error messages
+ xmlSetGenericErrorFunc(nullptr, xmlNullLogger);
+ }
+
+ // Shutdown libxml
+ void cleanupXML()
+ {
+ xmlCleanupParser();
+ }
+
} // namespace XML