From b3376bfe4e26591e1dc1066d8f2270baf4f9f759 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Mon, 23 Apr 2007 00:48:37 +0000 Subject: Merged Björn Steinbrinks improvements at the xml parsing from trunk version. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/configuration.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/configuration.cpp') diff --git a/src/configuration.cpp b/src/configuration.cpp index 53f6785e..d33df386 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -30,6 +30,7 @@ #include "log.h" #include "utils/tostring.h" +#include "utils/xml.h" void Configuration::init(const std::string &filename) { @@ -48,14 +49,14 @@ void Configuration::init(const std::string &filename) if (!doc) return; - xmlNodePtr node = xmlDocGetRootElement(doc); + xmlNodePtr rootNode = xmlDocGetRootElement(doc); - if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) { + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "configuration")) { logger->log("Warning: No configuration file (%s)", filename.c_str()); return; } - for (node = node->xmlChildrenNode; node != NULL; node = node->next) + for_each_xml_child_node(node, rootNode) { if (!xmlStrEqual(node->name, BAD_CAST "option")) continue; @@ -79,6 +80,8 @@ void Configuration::write() // Do not attempt to write to file that cannot be opened for writing FILE *testFile = fopen(mConfigPath.c_str(), "w"); if (!testFile) { + logger->log("Configuration::write() couldn't open %s for writing", + mConfigPath.c_str()); return; } else { @@ -87,8 +90,12 @@ void Configuration::write() xmlTextWriterPtr writer = xmlNewTextWriterFilename(mConfigPath.c_str(), 0); - if (!writer) + if (!writer) { + logger->log("Configuration::write() error while creating writer"); return; + } + + logger->log("Configuration::write() writing configuration..."); xmlTextWriterSetIndent(writer, 1); xmlTextWriterStartDocument(writer, NULL, NULL, NULL); @@ -96,9 +103,6 @@ void Configuration::write() for (OptionIterator i = mOptions.begin(); i != mOptions.end(); i++) { - logger->log("Configuration::write(%s, \"%s\")", - i->first.c_str(), i->second.c_str()); - xmlTextWriterStartElement(writer, BAD_CAST "option"); xmlTextWriterWriteAttribute(writer, BAD_CAST "name", BAD_CAST i->first.c_str()); -- cgit v1.2.3-70-g09d2