XPath normalize-space() to return a sequence of normalized strings

Fenixcan

New Member
I need to use the XPath function normalized-space() to normalize the text I want to extract from a XHTML document: http://test.anahnarciso.com/clean_bigbook_0.htmlI'm using the following expression:\[code\]//*[@slot="address"]/normalize-space(.)\[/code\]Which works perfectly in Qizx Studio, the tool I use to test XPath expressions.\[code\] let $doc := doc('http://test.anahnarciso.com/clean_bigbook_0.html') return $doc//*[@slot="address"]/normalize-space(.)\[/code\]This simple query returns a sequence of \[code\]xs:string\[/code\].\[code\]144 Hempstead Tpke403 West St880 Old Country Rd8412 164th St8412 164th St1 Irving Pl1622 McDonald Ave255 Conklin Ave22011 Hempstead Ave7909 Queens Blvd11820 Queens Blvd1027 Atlantic Ave1068 Utica Ave1002 Clintonville St1002 Clintonville St1156 Hempstead TpkeRoute 4910007 Rockaway Blvd12694 Willets Point Blvd343 James St\[/code\]Now, I want to use the previous expression in my Java code.\[code\]String exp = "//*[@slot=\"address"\"]/normalize-space(.)";XPath xpath = XPathFactory.newInstance().newXPath();XPathExpression expr = xpath.compile(exp);Object result = expr.evaluate(doc, XPathConstants.NODESET);\[/code\]But the last line throws an Exception:\[code\]Cannot convert XPath value to Java object: required class is org.w3c.dom.NodeList; supplied value has type xs:string\[/code\]Obvsiously, I should change \[code\]XPathConstants.NODESET\[/code\] for something; I tried \[code\]XPathConstants.STRING\[/code\] but it only returns the first element of the sequence.How can I obtain something like an array of Strings?Thanks in advance.
 
Back
Top