如何从Dom4j Node.selectObject或Node.selectNodes获取字符串列表 [英] How to get a list of String from Dom4j Node.selectObject or Node.selectNodes
问题描述
希望你有美好的一天.
Dom4j Javadoc表单 Node.selectObject(String xpathExpression)表示:
The Dom4j javadoc form Node.selectObject(String xpathExpression) says the following:
...返回的对象可以是一个或多个Node实例的列表,也可以是标量对象,例如 String 或Number实例,具体取决于XPath表达式.
...The object returned can either be a List of one or more Node instances or a scalar object like a String or a Number instance depending on the XPath expression.
但是,当我尝试在此xml上获取String列表时:
However when I try to get a list of String on this piece of xml:
<root>
...
<level1>
<property>pro1</property>
<property>pro1</property>
<property>pro1</property>
<level1>
...
</root>
具有以下代码:
List result = document.selectObject("/root/level1/property/text()")
我得到了 org.dom4j.tree.DefaultText 对象的列表.当然,我可以在列表上进行迭代,但是我想知道是否有一种获取String列表的方法.
I get a list of org.dom4j.tree.DefaultText objet. Of course I can iterate on the list but I yould like to know if there is a way to get a list of String.
推荐答案
来自 http://www.w3.org/TR/xpath/#section-简介
计算表达式以产生一个 对象,具有以下之一 四种基本类型:
An expression is evaluated to yield an object, which has one of the following four basic types:
- 节点集(无重复的无序节点集合)
- 布尔值(对或错)
- 数字(浮点数)
- 字符串(UCS字符序列)
- node-set (an unordered collection of nodes without duplicates)
- boolean (true or false)
- number (a floating-point number)
- string (a sequence of UCS characters)
因此,XPath 1.0中没有xs:string
的序列
So, no sequence of xs:string
in XPath 1.0
在XPath 2.0中,当然有一个序列数据类型...
In XPath 2.0 there is a sequence data type, of course...
这篇关于如何从Dom4j Node.selectObject或Node.selectNodes获取字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!