java bindings - Data types
Monday, 14 December 2020 · 2 messages · last reply 15 Dec 2020
AB
Andre Bovy14 Dec 2020 08:44 #
Dear BasexTalk,
for different (good or bad) reasons, I would like to use the java HTTPConnection instead of the http:client module.
But, I am not able to find the correct syntax for these statements. I have tried the middle dot character to force the correct type, without success
I receive always the message :
[XPTY0004] java.net.URL instance expected as first argument, xs:anyURI found.
Any idea?
Thank you in advance
declare namespace HttpURLConnection ="java.net.HttpURLConnection";
declare namespace URL ="java.net.URL";
let $urlString := "https:www.google.com"
let $url := URL:new($urlString)
let $httpConn := URL:openConnection($url)return $urlString
CG
Christian Grün15 Dec 2020 11:28 #
Hi André,
Some Java types are automatically converted to XQuery types [1]. It’s currently not possible to suppress the conversion.
If your code contains more than one, two Java calls, it’s usually cleaner to write some Java and XQuery wrapper code. For better packaging, the files can be embedded in a “combined module” [2].
Hope this helps,
Christian
[1] https://docs.basex.org/wiki/Java_Bindings#Data_Types
[2] https://docs.basex.org/wiki/Repository#Combined
Quoted text · Andre Bovy · 21 lines
On Mon, Dec 14, 2020 at 8:44 AM Andre Bovy <andre.bovy at gmail.com> wrote: > > Dear BasexTalk, > > for different (good or bad) reasons, I would like to use the java HTTPConnection instead of the http:client module. > But, I am not able to find the correct syntax for these statements. > I have tried the middle dot character to force the correct type, without success > I receive always the message : > [XPTY0004] java.net.URL instance expected as first argument, xs:anyURI found. > > Any idea? > Thank you in advance > > declare namespace HttpURLConnection ="java.net.HttpURLConnection"; > declare namespace URL ="java.net.URL"; > > let $urlString := "https:www.google.com" > let $url := URL:new($urlString) > let $httpConn := URL:openConnection($url) > > return $urlString
Written for BaseX 9.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery