Re: [xml] XPath Woes



mt2 wrote:
Hello all,

I'm working on a very simple project to parse ROAP messages, part of
the OMA DRM, for the moment. Libxml2 fits the bill for this project,
so thank you! I am using XPath to query the document:
/roap:riHello/extensions/extension[ xsi:type="roap:CertificateCaching"].
I am trying to get a node returned: <extension
xsi:type="roap:CertificateCaching" />. Unfortunately, I get no results
from libxml, but I have tested this against MSXML and an online XPath
environment. If anyone has any ideas, I'd appreciate it!


I tried your xml file and XPath query using the example program
'xpath1' included in libxml2 distribution, and got the following
results (note that the following command should all be on a single
line):

[bill bbxp work]$ ./xpath1 bug.xml
'/roap:riHello/extensions/extension[ xsi:type="roap:CertificateCaching"]'
"xsi=http://www.w3.org/2001/XMLSchema-instance
roap=urn:oma:bac:dldrm:roap-1.0"
Result (1 nodes):
= element node "extension"
[bill bbxp work]$

Perhaps you could analyze what is the difference between your code,
and the way in which this example program behaves (which appears to be
correct)?

The code:
 xpathCtx = xmlXPathNewContext(doc);
xmlXPathRegisterNs(xpathCtx, (xmlChar *)"roap", (xmlChar
*)"urn:oma:bac:dldrm:roap-1.0");
xmlXPathRegisterNs(xpathCtx, (xmlChar *)"xsi", (xmlChar
*)"http://www.w3.org/2001/XMLSchema-instance";);

xpathObj =
xmlXPathEvalExpression("/roap:riHello/extensions/extension[ xsi:type=\"roap:CertificateCaching\"]",
xpathCtx);

if (xpathObj->nodesetval->nodeNr > 0)

XML:
<?xml version="1.0" encoding="utf-8"?>
<roap:riHello xmlns:roap="urn:oma:bac:dldrm:roap-1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; status="Success"
sessionId="433211">
  <selectedVersion>1.0</selectedVersion>
  <riID>
    <keyIdentifier xsi:type="roap:X509SPKIHash">
      <hash>aXENc+Um/9/NvmYKiHDLaErK0gk</hash>
    </keyIdentifier>
  </riID>
  <riNonce>dsaiuiure9sdwerfqwer</riNonce>
  <trustedAuthorities>
    <keyIdentifier xsi:type="roap:X509SPKIHash">
      <hash>aXENc+Um/9/NvmYKiHDLaErK0gk</hash>
    </keyIdentifier>
    <keyIdentifier xsi:type="roap:X509SPKIHash">
      <hash>aXENc+Um/9/NvmYKiHDLaErK0gk</hash>
    </keyIdentifier>
  </trustedAuthorities>
  <extensions>
    <extension xsi:type="roap:CertificateCaching" />
  </extensions>
</roap:riHello>

Bill




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