Made the result of first XPath evaluation the same as those of the others Fixed a potential memory leak

This commit is contained in:
Zane U. Ji 2012-08-10 20:42:59 +08:00
parent cb82a3c856
commit 9a9cf0e724
2 changed files with 10 additions and 9 deletions

View File

@ -214,8 +214,7 @@ bool WrapLibxml::parse (
return false; return false;
} }
if ( indent ) xmlKeepBlanksDefault ( indent ? 0 : 1 );
xmlKeepBlanksDefault ( 0 );
xmlChar *buf = NULL; xmlChar *buf = NULL;
int size; int size;
@ -251,6 +250,8 @@ bool WrapLibxml::xpath ( const std::string& path, const std::string& fileName )
xmlParserCtxtPtr ctxt; xmlParserCtxtPtr ctxt;
xmlDocPtr docPtr; xmlDocPtr docPtr;
xmlKeepBlanksDefault ( 0 );
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if ( ctxt == NULL ) if ( ctxt == NULL )
{ {
@ -290,27 +291,27 @@ bool WrapLibxml::xpath ( const std::string& path, const std::string& fileName )
result = xmlXPathEvalExpression ( ( const xmlChar * ) path.c_str(), context ); result = xmlXPathEvalExpression ( ( const xmlChar * ) path.c_str(), context );
xmlKeepBlanksDefault ( 0 );
bool xpathIsValid = ( result ) ? true : false; bool xpathIsValid = ( result ) ? true : false;
while ( result != NULL ) while ( result != NULL )
{ {
if ( xmlXPathNodeSetIsEmpty ( result->nodesetval ) ) if ( xmlXPathNodeSetIsEmpty ( result->nodesetval ) )
break; break;
xmlBufferPtr bufferPtr = xmlBufferCreate();
if ( bufferPtr == NULL )
break;
nodeset = result->nodesetval; nodeset = result->nodesetval;
for ( int i = 0; i < nodeset->nodeNr; i++ ) for ( int i = 0; i < nodeset->nodeNr; i++ )
{ {
xmlNodePtr node = nodeset->nodeTab[i]; xmlNodePtr node = nodeset->nodeTab[i];
xmlBufferPtr bufferPtr = xmlBufferCreate(); if ( !node )
if ( !node || !bufferPtr )
break; break;
xmlNodeDump ( bufferPtr, NULL, node, 0, 1 ); xmlNodeDump ( bufferPtr, NULL, node, 0, 1 );
std::string nodeBuffer = ( const char * ) xmlBufferContent ( bufferPtr );
output += nodeBuffer; output += ( const char * ) xmlBufferContent ( bufferPtr );
output += '\n'; output += '\n';
} }
xmlBufferFree ( bufferPtr );
break; break;
} }
if ( result ) if ( result )

View File

@ -5840,7 +5840,7 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
std::string origEncoding = XmlEncodingHandler::get ( utf8Buffer ); std::string origEncoding = XmlEncodingHandler::get ( utf8Buffer );
XmlEncodingHandler::setUtf8 ( utf8Buffer, true ); XmlEncodingHandler::setUtf8 ( utf8Buffer, true );
std::auto_ptr<WrapExpat> wellformedparser ( new WrapExpat() ); std::auto_ptr<WrapExpat> wellformedparser ( new WrapExpat() );
if ( !wellformedparser->parse ( utf8Buffer ) ) // FIXME: Set encoding to UTF-8 before parsing. if ( !wellformedparser->parse ( utf8Buffer ) )
{ {
std::string error = wellformedparser->getLastError(); std::string error = wellformedparser->getLastError();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() ); wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );