Hi,
I'm using Xerces 2.7.0, with Visual Studio 2005.
I am experiencing what appears to be a heap corruption issue with the
DOMWriter in the code below, the error doesn't occur until main() is
exitting.
I read where others had similar issues, but their problems seemed to go away
when then added a call to release() of the DOMWriter. I have the call to
release and still have the same issue.
Does anyone see anything else I'm doing wrong?
Incidentally, I had the same issue with using the latest code from Xerces
3.0.0 and the DOMSerializer, so it might be something I'm not doing in terms
of memory for the std::string ..
Thanks,
-Westy
ERROR:
In dbgheap.c:
Windows has triggered a breakpoint in TestDomWriterD.exe.
This may be due to a corruption of the heap, and indicates a bug in
TestDomWriterD.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
CODE:
int
main(int argC, char* argV[])
{
std::string outXML;
std::string aggregationXml = fileToString("./data/stips.xml" );
AggregationEngine::parseTest(aggregationXml, outXML);
}
int AggregationEngine::parseTest(std::string &aggregationXML, std::string
&outXML)
{
outXML = domToString(aggregationXML);
}
std::string domToString(std::string &xmlSrc)
{
XercesDOMParser *parser;
std::string sXML;
DOMNode *doc;
try {
XMLPlatformUtils::Initialize();
} catch( const XMLException &toCatch) {
XERCES_STD_QUALIFIER cerr << StrX(toCatch.getMessage()) <<
XERCES_STD_QUALIFIER endl;
}
// Parse DOM
parser = new XercesDOMParser;
MemBufInputSource* memBufIS = new
MemBufInputSource((constXMLByte*)xmlSrc.c_str(), strlen(
xmlSrc.c_str()+1)*sizeof(char ), "xmlSrc", false );
parser->parse(*memBufIS);
delete memBufIS;
doc = parser->getDocument();
// Add Attributes
// - code removed for brevity
// Write DOM
try
{
XMLCh *pCore = XMLString::transcode("Core");
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(pCore);
DOMWriter *theWriter = impl->createDOMWriter();
XMLCh* xXml = theWriter->writeToString(*doc);
char *pChar = XMLString::transcode(xXml);
sXML = pChar;
XMLString::release(&pChar);
XMLString::release(&xXml);
XMLString::release(&pCore);
theWriter->release();
} catch (const XMLException& toCatch) {
XERCES_STD_QUALIFIER cerr << StrX(toCatch.getMessage ()) <<
XERCES_STD_QUALIFIER endl;
}
delete parser;
XMLPlatformUtils::Terminate();
return sXML;
}