LibXML找不到我的xpath表达式的任何节点 [英] LibXML doesn't find any nodes for my xpath expression

查看:81
本文介绍了LibXML找不到我的xpath表达式的任何节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iPhone应用程序中使用xpath和LibXML在xml文档中查找某些节点.我是xpath的菜鸟,所以我可能做错了什么.这是xml:

I'm using xpath and LibXML in an iPhone app to find some nodes in an xml document. I'm a noob in xpath so probably i am doing something wrong. Here is the xml:


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <GetUserByEmailResponse xmlns="http://tempuri.org/">
      <GetUserByEmailResult>
        <id>4006</id>
        <name>Kudor Gyozo</name>
        <email/>
        <image/>
        <facebookId>0</facebookId>
      </GetUserByEmailResult>
    </GetUserByEmailResponse>
  </soap:Body>
</soap:Envelope>

xpath表达式为//GetUserByEmailResult .没有节点返回.我希望重新获得< GetUserByEmailResult> .如果我在此处测试了相同的东西,就可以了.

The xpath expression is //GetUserByEmailResult. No nodes are returned. I expect to get <GetUserByEmailResult> back. If I test the same stuff here it works ok.

UPDATE1:这是我从.net Web服务获得的信息.有没有办法忽略libxml中的名称空间?

UPDATE1: This is what i get back from a .net web service. Is there a way to ignore namespaces in libxml?

推荐答案

GetUserByEmailResult 元素位于 http://tempuri.org/命名空间中,因此您需要将该名称空间添加到您的XPath搜索中.

The GetUserByEmailResult element is in the http://tempuri.org/ namespace so you would need to add that namespace to your XPath search.

您可以使用 xmlXPathRegisterNs 函数执行此操作:

You can do so using the xmlXPathRegisterNs function:

xmlXPathRegisterNs(context,  BAD_CAST "temp", BAD_CAST "http://tempuri.org/");

然后必须将您的XPath更改为

Then your XPath would have to be changed to

//temp:GetUserByEmailResult

这篇关于LibXML找不到我的xpath表达式的任何节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆