XPATH获取带命名空间节点注意事项

来源:互联网 发布:linux内核培训 编辑:程序博客网 时间:2024/05/17 05:56

参考来自:http://bbs.exmobi.cn/thread-811-1-1.html

当数据源中的xml存在命名空间时,应该注意xpath的写法,写法应注意以下几点:
1.       xpath取值节点和属性都必须是小写;
2.       xpath取值必须通过//*[local-name()=’XXX’]来获取节点;

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:chan="http://www.fiberhome.com/ChannelAccess/"><soapenv:Header/><soapenv:Body><chan:NotifyGatherMessage><ChannelId>c1</ChannelId><Username>xiaoming</Username><Password>123456</Password><Title>test</Title></chan:NotifyGatherMessage></soapenv:Body></soapenv:Envelope> 

xpath取值方法:aa.xpath("//*[local-name()='notifygathermessage']/username/text()","d1") 


如果要取NotifyGatherMessage节点和NotifyGatherMessage节点下的所有内容,取值表达式为:
aa.xpath("//*notifygathermessage") 


如果要提取notifygathermessage节点里边的所有内容不包括notifygathermessage节点,取值表达式为:



aa.xpath("//*notifygathermessage/*") 




0 0
原创粉丝点击