Hello,
I am calling a SOAP Web Service via http:send-request(...) method. It returns back base64 encoded XML.
Here is how I am converting it into XML: return html:parse(convert:binary-to-string(xs:base64Binary(http:send-request(...))) )
So, I am using three function/method calls: - xs:base64Binary() - convert:binary-to-string() - html:parse()
Is there a more straight forward method to convert base64 encoded string to XML in the BaseX 10.0?
Regards, Yitzhak Khabinsky
I need one particular base64 encoded XML element, i.e. <data>
The following call:
return inspect:type(http:send-request(...)//*:data)
returns the following: element()
From: Christian Grün christian.gruen@gmail.com Sent: Monday, August 15, 2022 1:39 PM To: Yitzhak Khabinsky ykhabins@bellsouth.net Cc: BaseX basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] Convert base64 to XML
It returns back base64 encoded XML.
Is it HTML or XML?
If you need to convert HTML, you can directly pass on binary data to html:parse.
What does inspect:type(http:send-request(...)[2]) return?
Best,
Christian
Thanks. If your data is HTML, html:parse is the correct choice. fetch:binary-doc can be used to convert a binary item to a document node [1]:
let $b64 := xs:base64Binary(<data>PHgvPg==</data>) return ( fetch:binary-doc($b64), html:parse($b64) )
[1] https://docs.basex.org/wiki/Fetch_Module#fetch:binary-doc
Mr. Grün,
As suggested, I tried the following, and it worked: return fetch:binary-doc(xs:base64Binary(http:send-request(...)//*:data)
It reduced three calls to two.
IMHO, it is a good idea to add such functionality to the Conversion Module: convert:base64-to-XML https://docs.basex.org/wiki/Conversion_Module
Much appreciated.
Regards, Yitzhak Khabinsky
-----Original Message----- From: Christian Grün christian.gruen@gmail.com Sent: Monday, August 15, 2022 2:19 PM To: Yitzhak Khabinsky ykhabins@bellsouth.net Cc: BaseX basex-talk@mailman.uni-konstanz.de Subject: Re: [basex-talk] Convert base64 to XML
Thanks. If your data is HTML, html:parse is the correct choice. fetch:binary-doc can be used to convert a binary item to a document node [1]:
let $b64 := xs:base64Binary(<data>PHgvPg==</data>) return ( fetch:binary-doc($b64), html:parse($b64) )
[1] https://docs.basex.org/wiki/Fetch_Module#fetch:binary-doc
basex-talk@mailman.uni-konstanz.de