如何通过 XPath 检索 CDATA 标记中的元素文本? [英] How do I retrieve element text inside CDATA markup via XPath?

查看:23
本文介绍了如何通过 XPath 检索 CDATA 标记中的元素文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下 xml 片段:

Consider the following xml fragment:

<Obj>
   <Name><![CDATA[SomeText]]></Name>
</Obj>

如何通过 XPath 检索SomeText"值?我正在使用 Nauman Leghari 的(优秀)Visual XPath 工具.
/Obj/Name 返回元素
/Obj/Name/text() 返回空白

How do I retrieve the "SomeText" value via XPath? I'm using Nauman Leghari's (excellent) Visual XPath tool.
/Obj/Name returns the element
/Obj/Name/text() returns blank

我不认为它是工具的问题(我可能是错的) - 我也读过 XPath 无法提取 CDATA(见最后回复 在这个线程中) - 这对我来说听起来有点奇怪.

I don't think its a problem with the tool (I may be wrong) - I also read XPath can't extract CDATA (See last response in this thread) - which sounds kinda weird to me.

推荐答案

我认为您引用的线程说 XPATH 忽略了 CDATA 标记本身,而不是 CDATA 标记中包含的文本.

i think the thread you referenced says that the CDATA markup itself is ignored by XPATH, not the text contained in the CDATA markup.

我的猜测是工具的问题,源代码可以下载,也许你可以调试一下...

my guess is that its an issue with the tool, the source code is available for download, maybe you can debug it...

这篇关于如何通过 XPath 检索 CDATA 标记中的元素文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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