Convert base64 to XML

Monday, 15 August 2022 · 5 messages
CG
Christian Grünin reply to ykhabins, 15 Aug 2022, 21:3415 Aug 2022 19:39 #
Quoted text · ykhabins · 1 line
> 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
CG
Christian Grünin reply to ykhabins, 15 Aug 2022, 22:1315 Aug 2022 20:18 #
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)
)
Y
ykhabins15 Aug 2022 21:34 #
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
Y
ykhabinsin reply to Christian Grün, 15 Aug 2022, 19:3915 Aug 2022 22:13 #
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()
Quoted text · Christian Grün · 11 lines
From: Christian Grün <christian.gruen at gmail.com> Sent: Monday, August 15, 2022 1:39 PM To: Yitzhak Khabinsky <ykhabins at bellsouth.net> Cc: BaseX <basex-talk at 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
Y
ykhabinsin reply to Christian Grün, 15 Aug 2022, 20:1815 Aug 2022 22:31 #
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
Quoted text · Christian Grün · 14 lines
-----Original Message----- From: Christian Grün <christian.gruen at gmail.com> Sent: Monday, August 15, 2022 2:19 PM To: Yitzhak Khabinsky <ykhabins at bellsouth.net> Cc: BaseX <basex-talk at 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

⚡Generated with XQuery