Project

Profile

Help

How to pass XML to Java function?

Added by Anonymous about 19 years ago

Legacy ID: #3130572 Legacy Poster: chris (chris1972)

Hi, I'm trying to pass some XML from my XSLT stylesheet to a user-defined static Java method, preferrebly as some kind of DOM node. I saw a few posts in this forum where it looks like people have gotten it to work just by declaring the method parameter as a org.w3c.dom.Node or org.w3c.dom.Document. Well I've tried this an many more things, but nothing works for me. I always get... "Cannot convert supplied XPath value to the required type for the extension function" exceptions. Let's take a simple example.... <xsl:variable name="javaTestVar"> <xml> <element value="a"/> <element value="b"/> </xml> </xsl:variable> What if I want to get $javaTestVar into my Java class as a DOM element? What should I do? Assuming this is no longer possible, I'd be fine with passing the XML as a String and constructing my own DOM. However, I don't even know how to do that. When I declare the parameter as String, I only get the inner text of the XML. I'm using Saxon 8.4. Any ideas? Thanks!


Replies (2)

RE: How to pass XML to Java function? - Added by Anonymous about 19 years ago

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

Have you tried using the -TJ option which shows you what Saxon is doing when it tries to bind extension functions? This sometimes provides the diagnostics you need. Have you got saxon8-dom.jar on the classpath? This contains all the classes needed to interface between Saxon and the DOM. Saxon now treats DOM as a third-party object model just like JDOM or XOM, and only recognizes DOM interfaces if these support classes are available.

RE: How to pass XML to Java function? - Added by Anonymous about 19 years ago

Legacy ID: #3131471 Legacy Poster: chris (chris1972)

Putting saxon8-dom.jar in the classpath did the trick. For some reason I always thought that saxon8.jar had all the libraries in it and you only used the other ones when you wanted to include only a subset of functionality in your app. In the future I'll try the -TJ for troubleshooting too. Thanks a bunch for your help.

    (1-2/2)

    Please register to reply