在XPath中如何选择元素内容

发布于 2024-08-26 05:01:14 字数 340 浏览 3 评论 0原文

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

例如,

<Element>xxx</Element>

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

编辑/答案

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

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

e.g.

<Element>xxx</Element>

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我心暖 2024-09-02 05:01:14

使用 value-of 元素:

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

如果您只能指定 XPath,则使用 text 函数,如下所示:

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

Use the value-of element:

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

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

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

追我者格杀勿论 2024-09-02 05:01:14

有点晚了,但是

data(Element)

……应该没问题。

A bit too late but...

data(Element)

...should also be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文