Re: [xsl] Convert JSON to XML?

Subject: Re: [xsl] Convert JSON to XML?
From: "Martynas Jusevičius martynas@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 2 May 2025 16:58:16 -0000
IMO the trouble of designing and implementing such a custom approach would
be greater than any benefit it would have over the standard json-to-xml().

On Fri, 2 May 2025 at 18.54, dvint dvint@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> I'm trying to find an xml result that is better than what json-to-xml()
> produces. I already have that approach working. I'm not trying for the
> perfect or correct interpretation of the json environment,  just something
> with more useful element names. Was that the map/map/map/string item, vs
> example/title
>
>
>
> Sent from my Verizon, Samsung Galaxy smartphone
>
>
> -------- Original message --------
> From: "Edward Porter edward.porter@xxxxxxx" <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>I
> Date: 5/2/25 6:02 AM (GMT-08:00)
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Convert JSON to XML?
>
> Regarding bloading into a Docker image for the production
implementationb,
> last year I presented at XML Prague
> <https://www.xmlprague.cz/day2-2024/#Containerizing> on containerizing
> XML build tools. You might try that path. You could easily build an image
> with Saxon and an XProc processor (like MorganaXProc), and the JVM of your
> choice. With those tools in place, you could write a pretty simple XProc
> pipeline to leverage the XSLT fn:json-to-xml
>
<https://www.saxonica.com/documentation12/index.html#!functions/fn/json-to-xm
l>
> to generate XML from your JSON inputs. If you pipelinebs simple enough,
you
> may be able to skip the XProc processor itself and just use Saxon directly.
> You can create the image such that itbs effectively a CLI tool rather
than
> a continuously running container by mounting the appropriate input and
> output volumes and configuring the parameters you need to pass to your
> pipeline in your dockerfile.
>
>
>
>
>
> On Thu, May 1, 2025 at 6:35b/PM dvint@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> I know (and have been using) the xlst json-to-xml() function for this
> purpose, but it is a pretty basic result. I happened to try the JSON to
> XML funtion in oXygen and got what I'd say is a much better result where
> I had some unique elemeent names instead of everything being a map or a
> string element.
>
> I was poking around to try and find a tool/library I could use in my
> conversion path and everything I'm finding is an online tool or has a
> price. Currently I'm developing a conversion pipeline and can leverage
> oXygen for this, but I need something I can build into a tool and load
> into a Docker image for the production implementation.
>
> Anyone have a suggestion?
>
>
>
> Hi Dan,
>
>
>
> It is not possible to map JSON to XML in a "correct" way because a JSON
> element can only be either a map or a list and not both whereas each XML
> element is both a map and a list.
>
> As a result there are many ways to represent the same data.
>
> And frequently what is perceived as "correct" is really not technically or
> conceptually.
> For example, it is commonplace to do something like the following:
>
> <address>
>   <street>123 Main St</street>
>   <city>Townville</city>
>   <state>PA</state>
> </address>
>
> IMO the "correct" form for an XML element is to put values that are not
> divisible into attributes which means the truely correct way to represent
> this data is:
>
> <address
>   street="123 Main St"
>   city="Townville"
>   state="PA"/>
>
> Anyway, my point is that the only "correct" way to convert JSON to XML is
> to understand in advance which of the many XML representations is "correct"
> for your particular application and then write code to explicitly perform
> that conversion.
>
> It's also not something that necessitates a third party tool as it is
> almost trivial to write code to recur through the JSON structure and emit
> XML text directly.
>
>
>
> Mike
>
>
>
> --
>
> Michael B Allen
> Java AD DS Integration
> https://www.ioplex.com/
>
<https://protect.checkpoint.com/v2/r01/___http://www.ioplex.com/___.YzJ1OnNhc
2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyNzk5Y2RlY2UzMTc6NzpmZDBhOjZjNG
M1MjI2ODIzNTBiYTc5N2U2YmRlYTlkYWY2OGYxZDU3Yzk2ZTE0NjE3NzkyODhmNWIzNTAyNzgzNGI
5ZWE6aDpUOk4>
>
> XSL-List info and archive
>
<https://protect.checkpoint.com/v2/r01/___http://www.mulberrytech.com/xsl/xsl
-list___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyNzk5Y2RlY2Uz
MTc6Nzo4YTg1OmM2OGU2NDdlN2VjMTAwZTkwMmE3N2MwZDY2N2FhMjhjNDI4OTliNGI0ZDAzNzcxO
GY3YWNhNzMxYTE5NjMzNGI6aDpUOk4>
>
> EasyUnsubscribe
>
<https://protect.checkpoint.com/v2/r01/___http://lists.mulberrytech.com/unsub
/xsl-list/965995___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyN
zk5Y2RlY2UzMTc6Nzo0ZDMzOmM5NmFhZjM5NjI0MjM1YTUxZmFiZGExN2RhZWRjMDVhY2QwZTQ4ZG
Y1MGI2YzMyNWM1ZTc5M2NiYTc5ZmUwNDE6aDpUOk4>
> (by email)
>
> XSL-List info and archive
>
<https://protect.checkpoint.com/v2/r01/___http://www.mulberrytech.com/xsl/xsl
-list___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUyNzk5Y2RlY2Uz
MTc6NzplYjRkOmIwMTk3YzM1ZTJhYTY3OWI1MjM2NDM1M2YwOWI1MWRjOWExMjY4ZjY4NGE1MDE2Y
mU1MGRjMmYxM2FlZDNkNjE6aDpUOk4>
>
> EasyUnsubscribe
>
<https://protect.checkpoint.com/v2/r01/___http://lists.mulberrytech.com/unsub
/xsl-list/3195664___.YzJ1OnNhc2luc3RpdHV0ZTpjOm86OTY4MWMzZGU5NGVlY2VlYzkzZDUy
Nzk5Y2RlY2UzMTc6Nzo1ZTEwOjlkN2RjYjY1ZTI4YjBjODg1ODgwNzZhNzg1MDZhYzUyNzA0NzI5M
WQ4YmJkNGNhZjUwMDdmMGExMmZiYWY1OTE6aDpUOk4>
> (by email)
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/1240222> (by
> email)
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/3206323> (by
> email <>)

Current Thread