[Libxmlplusplus-general] libxml++ issues (& bugs?)



Hi,

It's great to see libxml++ being maintained again. 
I've been using the library for a couple of years now, 
and find it very useful.  There are a few things here 
and there that are inconsistent, and I think need to 
be fixed.  I'll iterate through them with my proposed 
fixes.  

1. Behaviour of read_buffer() is not consistent with 
read() in that it does not have the 
xmlKeepBlanksDefault(0); clause.  This results in 
formatting problems when reading from memory.  To fix 
this I had to insert xmlKeepBlanksDefault(0); before 
line 81 of xml++.cc

2. Behaviour of write_buffer() is also not consistent 
with that of write() in that it performs 
xmlDocDumpMemory instead of xmlDocDumpFormatMemory.  
This results in formatting problems when dumping to 
memory.  To fix this problem, replace  xmlDocDumpMemory
(doc, (xmlChar **) &ptr, &len); with 
xmlDocDumpFormatMemory(doc, (xmlChar **) &ptr, &len, 
1); on line 131 of xml++.cc

3. Using free(ptr) on line 136 of xml++.cc is 
incorrect since ptr is allocated by libxml.  xmlFree
(ptr); should be used instead.

4. You can save some effort of maintaining an extra 
XMLNode constructor by using a default value for the 
line argument.   Get rid of XMLNode(const std::string 
&); constructor, and rewrite the XMLNode(const 
std::string &, int line); to XMLNode(const std::string 
&, int line = 0); in the header file.

5. I would rewrite writenode() like so: (comments 
accompany changes)

static void writenode(xmlDocPtr doc, XMLNode *n, 
xmlNodePtr p, int root) {
  XMLPropertyList props;
  XMLPropertyIterator curprop;
  XMLNodeList children;
  XMLNodeIterator curchild;
  xmlNodePtr node;

  if(root)
  {
    // root node can not have content, so we can 
safely change 
    // (xmlChar *) n->content().c_str() to NULL
    node = doc->children = xmlNewDocNode(doc, NULL,
						
				 (xmlChar *) n->name
().c_str(), 
						
				  NULL);
  }
  else 
  {
    // changed this because TEXT_NODE was not 
constructed properly in lxml++ 0.13
	// this resulted in a memory leak... 
    if(n->is_content()) 
    {
      node = xmlNewTextLen ((xmlChar *) n->content
().c_str(), n->content().length());
      xmlAddChild(p,node);
    }
    else 
    {
	  // xml formatting fixes in the if statement
	  // changed   (xmlChar *) n->content().c_str
() to NULL since n->is_content == false
      node = xmlNewChild(p, NULL, (xmlChar *) n->name
().c_str(), NULL);
    }
  }

  props = n->properties();
  for(curprop = props.begin(); curprop != props.end(); 
curprop++)
    xmlSetProp(node, (xmlChar *) (*curprop)->name
().c_str(),
		(xmlChar *) (*curprop)->value().c_str
());

  children = n->children();
  for(curchild = children.begin(); curchild != 
children.end(); curchild++)
    writenode(doc, *curchild, node);
}

There are also a couple of API extensions I think 
would be useful, but more on those later.

Thanks,

Greg




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]