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

View File

@ -5840,7 +5840,7 @@ void MyFrame::OnAssociate ( wxCommandEvent& event )
std::string origEncoding = XmlEncodingHandler::get ( utf8Buffer );
XmlEncodingHandler::setUtf8 ( utf8Buffer, true );
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();
wxString wideError = wxString ( error.c_str(), wxConvUTF8, error.size() );