我有下面提到的xml路径查询
//命名空间 char * pszNs_Soap_prefix =" s&#34 ;; char * pszNs_Soap_URL =" http://schemas.xmlsoap.org/soap/envelope/";
char * pszNs_SamlP_Prefix =" sp&#34 ;; char * pszNS_SamlP_URL =" urn:oasis:names:tc:SAML:1.0:protocol&#34 ;;
char * pszNS_Saml_Prefix =" sl&#34 ;; char * pszNS_Saml_URL =" urn:oasis:names:tc:SAML:1.0:断言&#34 ;;
char* pszXPathQuery3 = "/s:Envelope/s:Body/sp:Response/sl:Assertion/sl:AttributeStatement/s1:Attribute[@AttributeName='role']/sl:AttributeValue";
但是从xmlXPathEvalExpression库函数中获取NULL,上面是我的xpath查询,不知道我哪里出错了。
m_pXmlXPathObject = xmlXPathEvalExpression((XMLCHAR *)pszXPathQuery,m_pXmlXPathContext);
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>
答案 0 :(得分:0)
问题在于,在执行xpath查询之前,您需要注册名称空间。 xmlsoft.org网站提供了有关如何执行此操作的好示例!