在XPath中如何选择元素内容 [英] In XPath how to select the element content

查看:189
本文介绍了在XPath中如何选择元素内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种编写XPath表达式来选择元素内容的方法。

Is there a way of writing an XPath expression to select the content of the element.

例如

<Element>xxx</Element>

假设我可以编写XPath(/ Element)以获得 Element 如何调整XPath以获得返回的xxxx而不是元素包装器?

Assuming I can write XPath (/Element) to get Element how do I tweak the XPath to get xxxx returned rather than the Element wrapper?

EDIT / ANSWER

要在dom4j世界中执行此操作,请使用 Element.valueOf(String xpathExpression)而不是.selectXXX()方法。

To do this in dom4j world use the Element.valueOf(String xpathExpression) rather than the .selectXXX() methods.

推荐答案

使用 value-of 元素:

<xsl:value-of select="/Some/Path/To/Element"/>

如果只能指定XPath,则使用文本这样的功能:

If you can only specify an XPath then use the text function like this:


/ Some / Path / To / Element / text()

这篇关于在XPath中如何选择元素内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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