[libxml++] external entities substitution - libxml++ crashes



Hello libxmlplusplus-general,

I've run into an odd problem. I'm working with libxml++-1.0.4
and I need to load an XML document substituting all external entities.

Looking at the example in /dom_parse_entities I noticed that if I do
parser.set_substitute_entities(true), the program crashes.
I wrote the following small function using only libxml2 to load
a document with entities substition:

void parse_file_test(const std::string& filename)
{
  xmlParserCtxtPtr ctxt;
  xmlDocPtr doc;

  ctxt = xmlNewParserCtxt();
  if (ctxt == NULL) {
      std::cerr << "Failed to allocate parser context" << std::endl;
      return;
  }

  doc = xmlCtxtReadFile(ctxt, filename.c_str(), NULL, XML_PARSE_DTDVALID | XML_PARSE_NOENT );

  if (doc == NULL) {
    std::cerr << "Failed to parse " << filename << std::endl;
  } else {
    if (ctxt->valid == 0) {
      std::cerr << "Failed to validate " << filename << std::endl;
    } else {
      FILE* f = NULL;
      f = fopen("res.xml", "w");

      if (f) {
        xmlDocDump(f, doc);
        fclose(f);
      }
    }
    xmlFreeDoc(doc);
  }

  xmlFreeParserCtxt(ctxt);
}

and it worked just fine. 
I then added this very function to DomParser as a method DomParser::parse_file_test() and rebuilt libxml++.
I then called this method from a small program which used libxml++ and it crashed:

#0  0x00000019 in ?? ()
#1  0x0806a320 in xmlFreeNodeList (cur=0x82311a0) at tree.c:3282
#2  0x0804f1a6 in xmlFreeEntity (entity=0x821ffe8) at entities.c:72
#3  0x0806dff0 in xmlHashFree (table=0x821e7d0, f=0x804fb2c <xmlFreeEntityWrapper>) at hash.c:284
#4  0x0804fb53 in xmlFreeEntitiesTable (table=0x821e7d0) at entities.c:690
#5  0x08067f1c in xmlFreeDtd (cur=0x821e6e0) at tree.c:1023
#6  0x080680d4 in xmlFreeDoc (cur=0x821e570) at tree.c:1114
#7  0x08049bae in parse_file_test(std::string const&) (filename= 0xbffff7a0) at domparser.cc:277
#8  0x08048577 in main (argc=1, argv=0xbffff824) at main.cc:84
#9  0x081202e6 in __libc_start_main ()

Went into xmlFreeDoc never to return...

I then declared the method static in the DomParser class so as to
exclude object instantiation. The program crashed all the same. Finally I moved
parse_file_test() out of the DomParser class and declared it as a _function_.
Didn't help - the program would still crash.

Coming back to that libxml2 test that did work - I recompiled it with
parse_file_test() in a small library and it worked just fine. It looks like the
problem only arises when libxml++ is involved. So what am I doing wrong? My goal is to load
an XML document with DTD validation and substitution of external entities.

Thank you.  

-- 
Best regards,
 Igor                          mailto:ismolovski stbpwr com





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