0

How can I fetch remote XML from saxon?

thufir@dur:~/saxon$ 
thufir@dur:~/saxon$ java -cp /usr/share/java/Saxon-HE.jar net.sf.saxon.Query fetch.note.text.xq 
Static error on line 2 at column 2 of file:/home/thufir/saxon/fetch.note.text.xq near {...ww.w3schools.com/xml/note.x...} 
  XPST0081: Namespace prefix 'fetch' has not been declared
Static error(s) in query
thufir@dur:~/saxon$ 
thufir@dur:~/saxon$ cat fetch.note.text.xq 

fetch:xml("https://www.w3schools.com/xml/note.xml", map { 'chop': true() })


thufir@dur:~/saxon$ 

which works from BaseX.

Simple hello world runs okay:

thufir@dur:~/saxon$ 
thufir@dur:~/saxon$ java -cp /usr/share/java/Saxon-HE.jar net.sf.saxon.Query test.xq 
<?xml version="1.0" encoding="UTF-8"?><results><message>Hello World!</message></results>thufir@dur:~/saxon$ 
thufir@dur:~/saxon$ 

Might expath provide this functionality, perhaps? Or I should be using xslt for fetching.

Thufir
  • 8,216
  • 28
  • 125
  • 273

1 Answers1

1

Use standard XPath functions like doc('https://www.w3schools.com/xml/note.xml'). Processor specific modules like BaseX's fetch are usually not portable.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Exactly: standard XPath. Thanks. – Thufir Jan 02 '19 at 19:49
  • I am not sure why you have edited your question to now ask about the `doc` function I suggested, the XQuery code I suggested is as shown in my answer: `doc('https://www.w3schools.com/xml/note.xml')`. So your XQuery file (e.g. `foo.xq`) would contain that code and you would then call Saxon as you already do. e.g. `java -cp /usr/share/java/Saxon-HE.jar net.sf.saxon.Query foo.xq`. – Martin Honnen Jan 02 '19 at 20:51
  • I was running it with `java -jar ..` which barfed. Thought I had the query wrong, but it was the way I was invoking `Saxon`. Usage problem. I was trying to narrow the question by editing it. I'll change it back for reference -- maybe it will help someone else :) – Thufir Jan 02 '19 at 21:02