fix typos in d442190b
[ardour.git] / libs / pbd / xml++.cc
index 69187995a17fa31ca092d0e2e17990c3597ce46b..963531c5f5cca1c7d1880afcc18d36f5e4b28824 100644 (file)
@@ -42,7 +42,7 @@ XMLTree::XMLTree(const XMLTree* from)
        , _doc (xmlCopyDoc (from->_doc, 1))
        , _compression(from->compression())
 {
-       
+
 }
 
 XMLTree::~XMLTree()
@@ -82,26 +82,23 @@ XMLTree::read_internal(bool validate)
                _doc = 0;
        }
 
-       xmlParserCtxtPtr ctxt = NULL; /* the parser context */
+       /* create a parser context */
+       xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
+       if (ctxt == NULL) {
+               return false;
+       }
 
        xmlKeepBlanksDefault(0);
        /* parse the file, activating the DTD validation option */
        if (validate) {
-               /* create a parser context */
-               ctxt = xmlNewParserCtxt();
-               if (ctxt == NULL) {
-                       return false;
-               }
                _doc = xmlCtxtReadFile(ctxt, _filename.c_str(), NULL, XML_PARSE_DTDVALID);
        } else {
-               _doc = xmlParseFile(_filename.c_str());
+               _doc = xmlCtxtReadFile(ctxt, _filename.c_str(), NULL, XML_PARSE_HUGE);
        }
-       
+
        /* check if parsing suceeded */
        if (_doc == NULL) {
-               if (validate) {
-                       xmlFreeParserCtxt(ctxt);
-               }
+               xmlFreeParserCtxt(ctxt);
                return false;
        } else {
                /* check if validation suceeded */
@@ -114,10 +111,8 @@ XMLTree::read_internal(bool validate)
        _root = readnode(xmlDocGetRootElement(_doc));
 
        /* free up the parser context */
-       if (validate) {
-               xmlFreeParserCtxt(ctxt);
-       }
-       
+       xmlFreeParserCtxt(ctxt);
+
        return true;
 }
 
@@ -155,6 +150,20 @@ XMLTree::write() const
        xmlSetDocCompressMode(doc, _compression);
        writenode(doc, _root, doc->children, 1);
        result = xmlSaveFormatFileEnc(_filename.c_str(), doc, "UTF-8", 1);
+#ifndef NDEBUG
+       if (result == -1) {
+               xmlErrorPtr xerr = xmlGetLastError ();
+               if (!xerr) {
+                       std::cerr << "unknown XML error during xmlSaveFormatFileEnc()." << std::endl;
+               } else {
+                       std::cerr << "xmlSaveFormatFileEnc: error"
+                               << " domain: " << xerr->domain
+                               << " code: " << xerr->code
+                               << " msg: " << xerr->message
+                               << std::endl;
+               }
+       }
+#endif
        xmlFreeDoc(doc);
 
        if (result == -1) {
@@ -248,7 +257,7 @@ XMLNode::clear_lists ()
        _proplist.clear ();
 }
 
-XMLNode& 
+XMLNode&
 XMLNode::operator= (const XMLNode& from)
 {
        if (&from != this) {
@@ -257,17 +266,17 @@ XMLNode::operator= (const XMLNode& from)
                XMLPropertyIterator curprop;
                XMLNodeList nodes;
                XMLNodeIterator curnode;
-               
+
                clear_lists ();
 
                _name = from.name();
                set_content(from.content());
-               
+
                props = from.properties();
                for (curprop = props.begin(); curprop != props.end(); ++curprop) {
                        add_property((*curprop)->name().c_str(), (*curprop)->value());
                }
-               
+
                nodes = from.children();
                for (curnode = nodes.begin(); curnode != nodes.end(); ++curnode) {
                        add_child_copy(**curnode);
@@ -366,10 +375,10 @@ XMLTree::find(const string xpath, XMLNode* node) const
        } else {
                ctxt = xmlXPathNewContext(_doc);
        }
-       
+
        boost::shared_ptr<XMLSharedNodeList> result =
                boost::shared_ptr<XMLSharedNodeList>(find_impl(ctxt, xpath));
-       
+
        xmlXPathFreeContext(ctxt);
        if (doc) {
                xmlFreeDoc (doc);
@@ -425,7 +434,7 @@ XMLNode::add_property(const char* n, const string& v)
 {
        string ns(n);
         map<string,XMLProperty*>::iterator iter;
-       
+
         if ((iter = _propmap.find(ns)) != _propmap.end()) {
                 iter->second->set_value (v);
                 return iter->second;
@@ -662,11 +671,11 @@ XMLNode::dump (ostream& s, string p) const
                        s << " " << (*i)->name() << "=\"" << (*i)->value() << "\"";
                }
                s << ">\n";
-               
+
                for (XMLNodeList::const_iterator i = _children.begin(); i != _children.end(); ++i) {
                        (*i)->dump (s, p + "  ");
                }
-               
+
                s << p << "</" << _name << ">\n";
        }
 }