Convert base64 to XML
Monday, 15 August 2022 · 5 messages
CG
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,
ChristianCG
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 KhabinskyY
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
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 KhabinskyQuoted 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
Written for BaseX 10.0. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery