diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/xml.cpp | 53 | ||||
-rw-r--r-- | src/utils/xml.h | 17 |
2 files changed, 17 insertions, 53 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index a4a5360e..5d579ddc 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -30,62 +30,31 @@ namespace XML { - Document::Document(const std::string &filename, bool useResman): + Document::Document(const std::string &fileName, bool useResman): mDoc(0) { - int size; - char *data = NULL; + std::string resolvedFileName = fileName; if (useResman) { - data = ResourceManager::loadFile(filename, size); - } - else - { - std::ifstream file; - file.open(filename.c_str(), std::ios::in); + resolvedFileName = ResourceManager::resolve(fileName); - if (file.is_open()) + if (resolvedFileName.empty()) { - // Get length of file - file.seekg(0, std::ios::end); - size = file.tellg(); - file.seekg(0, std::ios::beg); - - data = (char*) malloc(size); - - file.read(data, size); - file.close(); - } - else - { - LOG_ERROR("(XML::Document) Error loading XML file: " - << filename); + LOG_ERROR("(XML::Document) File not found in search path: " + << fileName); + return; } } - if (data) - { - mDoc = xmlParseMemory(data, size); - free(data); + mDoc = xmlParseFile(resolvedFileName.c_str()); - if (!mDoc) - { - LOG_ERROR("(XML::Document) Error parsing XML file: " - << filename); - } - } - else + if (!mDoc) { - LOG_ERROR("(XML::Document) Error loading XML file: " - << filename); + LOG_ERROR("(XML::Document) Error parsing XML file: " + << resolvedFileName); } } - Document::Document(const char *data, int size) - { - mDoc = xmlParseMemory(data, size); - } - Document::~Document() { if (mDoc) diff --git a/src/utils/xml.h b/src/utils/xml.h index eba88e56..2278ce46 100644 --- a/src/utils/xml.h +++ b/src/utils/xml.h @@ -40,19 +40,14 @@ namespace XML { public: /** - * Constructor that attempts to load the given file through the - * resource manager. Logs errors. - */ - Document(const std::string &filename, bool useResman = true); - - /** - * Constructor that attempts to load an XML document from memory. - * Does not log errors. + * Attempts to load an XML document from the given file. Logs an + * error when something went wrong. * - * @param data the string to parse as XML - * @param size the length of the string in bytes + * @param fileName the file name of the XML document + * @param useResman whether to resolve the full path to the file + * using the resource manager (true by default). */ - Document(const char *data, int size); + Document(const std::string &fileName, bool useResman = true); /** * Destructor. Frees the loaded XML file. |