无法使用 libxml2 处理 xpath 查询
Not able to process xpath query using libxml2
我在下面提到了xml路径查询
//Namespace 字符* pszNs_Soap_prefix = "s"; 字符* pszNs_Soap_URL = "http://schemas.xmlsoap.org/soap/envelope/";
字符* pszNs_SamlP_Prefix = "sp"; char* pszNS_SamlP_URL = "urn:oasis:names:tc:SAML:1.0:protocol";
字符* pszNS_Saml_Prefix = "sl"; 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";
但是从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>
问题是您需要在执行 xpath 查询之前注册命名空间。 xmlsoft.org 网站提供了一个关于如何执行此操作的很好的例子!
http://xmlsoft.org/examples/xpath1.c
相关文章:
- 警告处理为错误这里有什么问题
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 使用流处理接收到的数据
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 基于多个条件处理地图中的所有元素
- 如何用数字处理log(0)
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- 错误处理.将系统错误代码映射到泛型
- 从文本文件中读取时钟时间和事件时间并进行处理
- 在运行时处理类型擦除的数据-如何不重新发明轮子
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 用于矢量处理的多个线程
- 对字符串进行排序时,在c++中处理sort()
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- 处理除以零会导致<csignal>意外行为
- 是否可以在c++中处理字符串流中的各个元素
- 无法使用 libxml2 处理 xpath 查询