X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fxml%2B%2B.cc;h=5fb777bdc77444b6c989dc0548c4c9fdc7097242;hb=480f1e408211b8d3acdf0af41291e14ad47d2126;hp=7c6fffe7f80adda07cd478cf11bfb3baa14c4326;hpb=6262eae7c0e4bf515d29775dc521e3c5f436b50b;p=ardour.git diff --git a/libs/pbd/xml++.cc b/libs/pbd/xml++.cc index 7c6fffe7f8..5fb777bdc7 100644 --- a/libs/pbd/xml++.cc +++ b/libs/pbd/xml++.cc @@ -5,12 +5,13 @@ * Modified for Ardour and released under the same terms. */ +#include #include "pbd/xml++.h" #include #include #include -#define XML_VERSION "1.0" +xmlChar* xml_version = xmlCharStrdup("1.0"); using namespace std; @@ -130,7 +131,7 @@ XMLTree::read_buffer(const string& buffer) delete _root; _root = 0; - doc = xmlParseMemory((char*)buffer.c_str(), buffer.length()); + doc = xmlParseMemory(const_cast(buffer.c_str()), buffer.length()); if (!doc) { return false; } @@ -150,10 +151,24 @@ XMLTree::write() const int result; xmlKeepBlanksDefault(0); - doc = xmlNewDoc((xmlChar*) XML_VERSION); + doc = xmlNewDoc(xml_version); 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) { @@ -166,15 +181,17 @@ XMLTree::write() const void XMLTree::debug(FILE* out) const { +#ifdef LIBXML_DEBUG_ENABLED xmlDocPtr doc; XMLNodeList children; xmlKeepBlanksDefault(0); - doc = xmlNewDoc((xmlChar*) XML_VERSION); + doc = xmlNewDoc(xml_version); xmlSetDocCompressMode(doc, _compression); writenode(doc, _root, doc->children, 1); xmlDebugDumpDocument (out, doc); xmlFreeDoc(doc); +#endif } const string& @@ -187,7 +204,7 @@ XMLTree::write_buffer() const XMLNodeList children; xmlKeepBlanksDefault(0); - doc = xmlNewDoc((xmlChar*) XML_VERSION); + doc = xmlNewDoc(xml_version); xmlSetDocCompressMode(doc, _compression); writenode(doc, _root, doc->children, 1); xmlDocDumpMemory(doc, (xmlChar **) & ptr, &len); @@ -357,7 +374,7 @@ XMLTree::find(const string xpath, XMLNode* node) const xmlDocPtr doc = 0; if (node) { - doc = xmlNewDoc((xmlChar*) XML_VERSION); + doc = xmlNewDoc(xml_version); writenode(doc, node, doc->children, 1); ctxt = xmlXPathNewContext(doc); } else { @@ -555,7 +572,7 @@ readnode(xmlNodePtr node) xmlAttrPtr attr; if (node->name) { - name = (char*)node->name; + name = (const char*)node->name; } tmp = new XMLNode(name); @@ -565,7 +582,7 @@ readnode(xmlNodePtr node) if (attr->children) { content = (char*)attr->children->content; } - tmp->add_property((char*)attr->name, content); + tmp->add_property((const char*)attr->name, content); } if (node->content) { @@ -591,9 +608,9 @@ writenode(xmlDocPtr doc, XMLNode* n, xmlNodePtr p, int root = 0) xmlNodePtr node; if (root) { - node = doc->children = xmlNewDocNode(doc, 0, (xmlChar*) n->name().c_str(), 0); + node = doc->children = xmlNewDocNode(doc, 0, (const xmlChar*) n->name().c_str(), 0); } else { - node = xmlNewChild(p, 0, (xmlChar*) n->name().c_str(), 0); + node = xmlNewChild(p, 0, (const xmlChar*) n->name().c_str(), 0); } if (n->is_content()) { @@ -603,7 +620,7 @@ writenode(xmlDocPtr doc, XMLNode* n, xmlNodePtr p, int root = 0) props = n->properties(); for (curprop = props.begin(); curprop != props.end(); ++curprop) { - xmlSetProp(node, (xmlChar*) (*curprop)->name().c_str(), (xmlChar*) (*curprop)->value().c_str()); + xmlSetProp(node, (const xmlChar*) (*curprop)->name().c_str(), (const xmlChar*) (*curprop)->value().c_str()); } children = n->children();