Hi all,
I use the
xmlXPathEvalExpression to retrieval my xml file.
But there is one problem to
confused me lots of time.
Here is my code
below this line.
=======================================================================================
xmlXPathContextPtr xpathCtx;
xmlXPathObjectPtr xpathObj; xpathCtx =
xmlXPathNewContext(doc);
if(xpathCtx == NULL) { fprintf(stderr,"Error: unable to create new XPath context\n"); return(-1); } xpathObj =
xmlXPathEvalExpression((xmlChar *) "//EncryptedKey",
xpathCtx);
if(xpathObj == NULL) { fprintf(stderr,"Error: unable to evaluate xpath _expression_ \"%s\"\n"); xmlXPathFreeContext(xpathCtx); return(-1); } printf("nodeset number : %d\n",
xpathObj->nodesetval->nodeNr);
Here is my xml file content below this
line.
=========================================================================================
<XMLEncRoot>
<EncryptedKey Id="EK_EncKeyA" xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/> <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:KeyName>strKey_A</ds:KeyName> <ds:X509Data> <ds:X509Certificate>MIIEvDCCA6SgAwIBAgIEP30mzDANBgkqhkiG9w0BAQUFADBhMQswCQYDVQQGEwJU VzEbMBkGA1UEChMSVEFJV0FOLUNBLkNPTSBJbmMuMRgwFgYDVQQLEw9FdmFsdWF0 aW9uIE9ubHkxGzAZBgNVBAMTElRhaUNBIFRlc3QgRlhNTCBDQTAeFw0wMzEwMDMw NzM1NDBaFw0wNDEwMDIwNzM1NDBaMHYxCzAJBgNVBAYTAlRXMRAwDgYDVQQKEwdG aW5hbmNlMRswGQYDVQQLExJUYWlDQSBUZXN0IEZYTUwgQ0ExFTATBgNVBAsTDDIz MjE4MTgzLUZTQzEMMAoGA1UECxMDTUlTMRMwEQYDVQQDEwpNMjQyNTQ5NTg3MIGf MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDehBRUX4PtRPn1Z+XESHr9UouU2ZWN UGa58s1rwXp18esH8os+J+z68Omy+4p9PN/70Xjazbi49Id+wMJK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lKbMR1NhXwe3oBWLcOPpuPIPyEHdFAPFmjvY LIxdY4P6z+eDJ2IH1r7Nrw==</ds:X509Certificate> </ds:X509Data> </ds:KeyInfo> <CipherData> <CipherValue/> </CipherData> <CarriedKeyName>Co-Encrypt</CarriedKeyName> </EncryptedKey> </XMLEncRoot>
======================================================================================================
the response is : "nodeset number : 0"
I want to get the "EncryptedKey" node, but the nodeset
seems to get nothing.
I have been confused for three days.
I don't know what's wrong with my code.
I use libxml2 of 2.6.12.
Can anyone to tell me what's the problem of my code? Thanks very
much.
|