2

Hope you have a good day.

The Dom4j javadoc form Node.selectObject(String xpathExpression) says the following:

...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.

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>

with the following code:

List result = document.selectObject("/root/level1/property/text()")

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.

1 Answer 1

0

From http://www.w3.org/TR/xpath/#section-Introduction

An expression is evaluated to yield an object, which has one of the following four basic types:

  • node-set (an unordered collection of nodes without duplicates)
  • boolean (true or false)
  • number (a floating-point number)
  • string (a sequence of UCS characters)

So, no sequence of xs:string in XPath 1.0

In XPath 2.0 there is a sequence data type, of course...

Sign up to request clarification or add additional context in comments.

2 Comments

I'm using xpath 2.0. I don't understand your answer. Even if an expression is evaluated to yield and object of the described type, Dom4j Api should return a list of string isn't it.
@Periworks: If you are selecting XML nodes the result should be a List of Node from dom4j.sourceforge.net/dom4j-1.4/apidocs/org/dom4j/… . Also do note that this method is deprecated in favor of evaluate and there is no indication that a dom4j interface can work with an XPath 2.0 engine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.