[xml] XPath and namespaces in _created_ document



Hi,
I know that is annoying, I saw a lot of posting in July-August, and I
already checked all of them, but cannot find answer to my problem.
The difference that I'm trying to evaluate XPath expression against new
(created by xmlNewDoc) document.
The same expressions work fine on parsed documents, but return nothing on
new.
xml is:

<Envelope>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#";>
<XPath xmlns:dsig="http://www.w3.org/2000/09/xmldsig#";>
</XPath>
</Signature>
</Envelope>

and expression:
"(//. | //@* | //namespace::*)[ancestor-or-self::dsig:Signature]"

Here is a sequence of statements I used to create XML:
        thisDoc = xmlNewDoc("1.0");
        root = xmlNewDocNode(thisDoc,NULL,"Envelope",NULL);
        xmlDocSetRootElement(thisDoc,root);
        sig = xmlNewNode(NULL,"Signature");
        xmlNewNs(sig,"http://www.w3.org/2000/09/xmldsig#",NULL);
        xmlAddChild(root,sig);

        cur = xmlNewNode(NULL,"XPath");
        xmlNewNs(cur,"http://www.w3.org/2000/09/xmldsig#","dsig";);
        xmlAddChild(sig,cur);

First I tried
        xmlXPathRegisterNs(xpathCtx,"dsig","http://www.w3.org/2000/09/xmldsig#";);
before evaluating expression (which works perfect on parsed documents). But
it didn't bring any result.

Then, as mentioned in
http://mail.gnome.org/archives/xml/2001-July/msg00097.html,
I passed namespaces to xmlXPathContext:

    nsNr = 0;
    nsList = xmlGetNsList(cur->doc, cur);
    if (nsList != NULL) {
        while (nsList[nsNr] != NULL)
            nsNr++;
    }
        xpathCtx->namespaces = nsList;
        xpathCtx->nsNr = nsNr;

And this one also did not help.
What am I doing wrong?

Thank you,
Alex




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