I need to use the standard XPath function normalized-space () to normalize the text I want to extract from an XHTML document: http://test.anahnarciso.com/clean_bigbook_0.html
I use the following expression:
//*[@slot="address"]/normalize-space(.)
Which works great in Qizx Studio, the tool I use to test XPath expressions.
let $doc := doc('http://test.anahnarciso.com/clean_bigbook_0.html')
return $doc//*[@slot="address"]/normalize-space(.)
This simple query returns a sequence xs:string.
144 Hempstead Tpke
403 West St
880 Old Country Rd
8412 164th St
8412 164th St
1 Irving Pl
1622 McDonald Ave
255 Conklin Ave
22011 Hempstead Ave
7909 Queens Blvd
11820 Queens Blvd
1027 Atlantic Ave
1068 Utica Ave
1002 Clintonville St
1002 Clintonville St
1156 Hempstead Tpke
Route 49
10007 Rockaway Blvd
12694 Willets Point Blvd
343 James St
Now I want to use the previous expression in my Java code.
String exp = "//*[@slot=\"address"\"]/normalize-space(.)";
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile(exp);
Object result = expr.evaluate(doc, XPathConstants.NODESET);
But the last line throws an exception:
Cannot convert XPath value to Java object: required class is org.w3c.dom.NodeList; supplied value has type xs:string
Obviously, I have to change something XPathConstants.NODESET; I tried XPathConstants.STRING, but it only returns the first element of the sequence.
How can I get something like an array of strings?
Thanks in advance.