Project

Profile

Help

fn:data function through Java problem

Added by Anonymous over 16 years ago

Legacy ID: #5116964 Legacy Poster: aodhol (aodhol)

Hello, I'm trying to get a concatenated string of values from an XML doc using the XPath data(//ps) function through Java. I have tested the expression in my editor (Oxygen) and I retrieve a list of values as expected. If I use: String psVal=xpath.evaluate("data(//ps"),document,XPathConstants.STRING).toString(); I get the first value on the list. I then tried the following: NodeList list=(NodeList) xpath.evaluate(xpathExpressionStr,document,XPathConstants.NODESET) and got an exception: Caused by: net.sf.saxon.trans.XPathException: Extension function required class org.w3c.dom.NodeList; supplied value of class net.sf.saxon.value.UntypedAtomicValue could not be converted. I'm new to Saxon and XPath. How should I be doing this? Thanks, Aodh.


Replies (3)

Please register to reply

RE: fn:data function through Java problem - Added by Anonymous over 16 years ago

Legacy ID: #5118008 Legacy Poster: Michael Kay (mhkay)

The JAXP API for XPath is designed for XPath 1.0, which only has four data types: number, boolean, string, and node-set. I really wouldn't recommend using it if you want to execute XPath 2.0 expressions that return other types (in this case a sequence of strings). I've tried to adapt the definitions of the API to 2.0 while remaining conformant, but it's clumsy. So I would recommend that you use the s9api interface for XPath instead: it is a much cleaner design and much better suited to working with XPath 2.0. Having said that, I'm not sure exactly why you are getting this message. But you haven't shown me enough of your code, for example I can't see what's in xPathExpressionStr. (And the code you have shown appears to have been edited: the expression "data(//ps" is missing a close paren. By all means simplify your code before submitting it, but please make sure it still exhibits the same problem and not a different problem.) Michael Kay

RE: fn:data function through Java problem - Added by Anonymous over 16 years ago

Legacy ID: #5119771 Legacy Poster: aodhol (aodhol)

Thanks Michael, I simplified the example for the post and only noticed the typos after posting! I tried out the s9api and may go with that although it may be too much for my needs (extracting info in many possible markup variations from TEI XML files) and level of XML parsing/XPath experience. I was keen to remain with JAXP or equivalent for vendor neutrality. Keep up the good work! A.

RE: fn:data function through Java problem - Added by Anonymous over 16 years ago

Legacy ID: #5121632 Legacy Poster: Michael Kay (mhkay)

You can post attachments in the support-requests tracker on SourceForge, or you can send them to me privately if you prefer to keep them private - mike at saxonica dot com

    (1-3/3)

    Please register to reply