Re: [xml] Usage of xmlSaveTree() proper?



Thanks. I added  -

    xbuf = xmlBufferCreate();
    xmlNodePtr node = nodes->nodeTab[0];
sCtxt = xmlSaveToBuffer(xbuf,NULL,0);
    xmlSaveTree(sCtxt,node);

and I still get the same error.

Curiously, now xmlElemDump() also doesnt work!

-KK

On 8/29/07, Lars Oppermann <Lars Oppermann sun com> wrote:
You are passing an uninitialized variable sCtxt to xmlSaveTree. I'd
suggest you take a look at the documentation on xmlSaveTo... functions,
e.g.
xmlSaveCtxtPtr xmlSaveToBuffer(
    xmlBufferPtr buffer,
    const char * encoding,
    int options)
at http://www.xmlsoft.org/html/libxml-xmlsave.html

Furthermore, when accessing the XPath query, you may want to use
xmlXPathNodeSetItem see
http://www.xmlsoft.org/html/libxml-xpath.html#xmlXPathNodeSetItem) and
do proper error checking (but you were going to add that later anyway,
weren't you? ;)

HTH
Lars

Krishna Kumar wrote:
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
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml





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