Question

I trying to write Java code to use BaseX in local mode to query XML returned by hitting a web service.

I'm not sure about the different ways of passing the XML. Should I

  1. bind an external variable with XML data and pass to XQuery, and then use fn:parse(),
  2. use the fetch module,
  3. or is there any other better way of doing it?

Is there any other XQuery 3.0 processor with similar capabilities and in built modules?

Was it helpful?

Solution

Solution 1: Binding an external variable

This means you will first have to store the XML data as java variable and then pass it on to BaseX. You can certainly do so, it will look something like that:

declare variable $t as xs:string external;
parse-xml($t)

Solution 2: Use fetch()

fetch:text() and fetch:binary() are streamable, but parse-xml will materialize the string (be careful, the function is called parse-xml() not parse() as stated in your question.

parse-xml(fetch:text("YOUR-URI"))

Solution 3: Getting the data directly within XQuery

You can also simply retrieve your data from the web service using the http module:

http:send-request(<http:request method='get'></http:request>, "YOUR-URI")[2]

Solution 3 seems to me the easiest way, if you don't further need this result in the Java code. Otherwise you might want to stick to solution 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top