[英]Not able to process xpath query using libxml2
I have below mentioned xml path query 我下面有提到的xml路径查询
//Namespace char* pszNs_Soap_prefix = "s"; //命名空间char * pszNs_Soap_prefix =“ s”; char* pszNs_Soap_URL = " http://schemas.xmlsoap.org/soap/envelope/ "; char * pszNs_Soap_URL =“ http://schemas.xmlsoap.org/soap/envelope/ ”;
char* pszNs_SamlP_Prefix = "sp"; char * pszNs_SamlP_Prefix =“ sp”; char* pszNS_SamlP_URL = "urn:oasis:names:tc:SAML:1.0:protocol"; char * pszNS_SamlP_URL =“ urn:oasis:names:tc:SAML:1.0:protocol”;
char* pszNS_Saml_Prefix = "sl"; char * pszNS_Saml_Prefix =“ sl”; char* pszNS_Saml_URL = "urn:oasis:names:tc:SAML:1.0:assertion"; char * pszNS_Saml_URL =“ urn:oasis:names:tc:SAML:1.0:assertion”;
char* pszXPathQuery3 = "/s:Envelope/s:Body/sp:Response/sl:Assertion/sl:AttributeStatement/s1:Attribute[@AttributeName='role']/sl:AttributeValue";
but getting NULL from xmlXPathEvalExpression library function,above is my xpath query, don't know where i am going wrong. 但是从xmlXPathEvalExpression库函数获取NULL,上面是我的xpath查询,不知道我要去哪里。
m_pXmlXPathObject=xmlXPathEvalExpression((xmlChar*)pszXPathQuery,m_pXmlXPathContext); m_pXmlXPathObject = xmlXPathEvalExpression((xmlChar *)pszXPathQuery,m_pXmlXPathContext);
XML string XML字符串
<saml:Assertion MajorVersion="1"
MinorVersion="1"
AssertionID="_a75adf55-01d7-40cc-929f-dbd8372ebdfc"
Issuer="SAML_AUTH_URI"
IssueInstant="2005-06-08T12:00:01.100Z">
<saml:AuthenticationStatement
AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:password"
AuthenticationInstant="2005-06-08T11:59:59.000Z">
<saml:Subject>
<saml:NameIdentifier>jre</saml:NameIdentifier>
</saml:Subject>
</saml:AuthenticationStatement>
<saml:AttributeStatement>
<saml:Attribute
AttributeName="role"
AttributeNamespace="oasis:names:tc:xacml:2.0:subject">
<saml:AttributeValue>weboamadmin</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The problem is that you need to register your name spaces BEFORE you execute your xpath query. 问题是执行xpath查询之前需要注册名称空间。 The xmlsoft.org website gives a good example on how to perform this! xmlsoft.org网站提供了有关如何执行此操作的很好的示例!
http://xmlsoft.org/examples/xpath1.c http://xmlsoft.org/examples/xpath1.c
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.