int ConvertXMLTreeToC14Bytes(xmlNodePtr pNode , xmlChar **ppBuffer )
{
if(pNode == NULL || ppBuffer == NULL)
return -1 ;
int bytesWritten = 0;
xmlDocPtr pDoc = NULL ;
xmlDocPtr newDoc = NULL ;
// if our parent is the doc node then this is top of tree
if(pNode->doc->children == pNode)
{
pDoc = pNode->doc ;
}
else
{
// This is a node other than the topmost node
// we create a new document with this node as the root
// create a new Doc
newDoc = xmlNewDoc((const xmlChar *)"1.0");
if(newDoc == NULL)
return -1 ;
// copy our node contents to a node under the new doc (newDoc)
// Create a copy of the node
xmlNodePtr newNode = xmlDocCopyNodeList(newDoc , pNode );
if(newNode == NULL)
{
xmlFreeDoc(newDoc);
return -1;
}
// Add a new node as top of tree for this new doc !
//xmlDocSetRootElement(newDoc , newNode);
pDoc = newDoc ;
}
// now create canonical form
// doc , All nodes ( NULL) , Exclusive canonicalization , no inclusive namespaces , NO comments in the result , ptr to client buffer ptr
bytesWritten = xmlC14NDocDumpMemory(pDoc , NULL , 1, NULL, 0, ppBuffer);
if(newDoc)
{
xmlFreeDoc(newDoc) ;
newDoc = NULL ;
}
pDoc = NULL ;
return bytesWritten ;
}
Am I missing something here ? Any reason why I would be leaking some heap ?
Thanks