[xml] Usage of xmlSaveTree() proper?



Hi,

Am I using xmlSaveTree() properly in the following example? I am
getting a "Internal error, no document" error on running this piece of
code.

Or is something else throwing that error? I am simply trying to
extract a node and its decendants and storing them in a buffer, so i
can use them in a string for later. BTW, the commented call to
xmlElemDump() works.

void SAMLAssertion::parse_assertion(const String &source) {

    XMLPlatformUtils::Initialize();
    xmlDocPtr doc;
    xmlXPathContextPtr xpathCtx;
    xmlXPathObjectPtr xpathObj;

    xmlSaveCtxtPtr sCtxt;
    xmlBufferPtr xbuf;

    doc = xmlParseMemory(source.chars(), source.length());

    xpathCtx = xmlXPathNewContext(doc);

    xmlXPathRegisterNs(xpathCtx, (const xmlChar* )"ds", (const
xmlChar* )"http://www.w3.org/2000/09/xmldsig#";);
    xmlXPathRegisterNs(xpathCtx, (const xmlChar* )"saml", (const
xmlChar* )"urn:oasis:names:tc:SAML:2.0:protocol");

    xpathObj = xmlXPathEvalExpression((const xmlChar*
)"/ds:SignedInfo/descendant-or-self::node()", xpathCtx);

   xmlNodeSetPtr nodes = xpathObj->nodesetval;

    xbuf = xmlBufferCreate();
    xmlNodePtr node = nodes->nodeTab[0];
    xmlSaveTree(sCtxt,node);
//xmlElemDump(stdout,doc,nodes->nodeTab[0]);

    xmlSaveClose(sCtxt);
    xmlFreeDoc(doc);
    xmlBufferFree(xbuf);
    XMLPlatformUtils::Terminate();

}

Thanks,
Krishna Kumar



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