xsl-list
[Top] [All Lists]

Re: [xsl] JSON to XML using XSLT 3.0 representation

2020-07-13 10:26:43
Hi,

sure enough I hit one of the 0.1% cases in the conversion :) Namely
the form feed char being present in the JSON which produced form feed
in the XML output which is not well-formed XML 1.0.

I've released JSON2XML version 1.0.5 which attempts to address this
issue by doing the default replacement of invalid characters to the
REPLACEMENT CHARACTER (xFFFD), as specified by the json-to-xml()
function.

Could you please take a look at the replacement code (copy-pasted from
StackOverflow :)) - does it look reasonable?
https://github.com/AtomGraph/JSON2XML/blob/master/src/main/java/com/atomgraph/etl/json/JsonStreamXMLWriter.java#L237


On Wed, Mar 27, 2019 at 12:54 AM Michael Kay mike(_at_)saxonica(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Nice.

You're not handling the edge cases such as duplicate keys, characters invalid 
in XML, unpaired surrogates, etc, but I should think that's OK 99.9% of the 
time.

Being able to write to a SAX ContentHandler might be more versatile than a 
StAX XMLStreamWriter, since there are probably more things prepared to take 
input from a SAX source without having to serialize the XML first.

Michael Kay
Saxonica

On 26 Mar 2019, at 22:55, Martynas Jusevičius 
martynas(_at_)atomgraph(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi all,

I wanted to share a small utility I've created for our XML pipeline:
https://github.com/AtomGraph/JSON2XML

It is a streaming JSON to XML converter. It reads any JSON data and
produces XML Representation of JSON specified in XSLT 3.0 [1].

JSON2XML enables JSON transformation with XSLT even without having an
XSLT 3.0 processor. You can simply pre-process the data by having
JSON2XML before the transformation, and pipeline it into an XSLT 2.0
stylesheet, for example. That way your stylesheet stays forward
compatible with XSLT 3.0, as the XML representation is exactly the
same.

Admittedly I haven't done much testing, but I'm going to put into use
next month. The sample from the specification works :) The conversion
code is quite straightforward.

Also planning to create a Docker container out of it.

Feedback and pull requests are welcome.

[1] https://www.w3.org/TR/xslt-30/#json-to-xml-mapping

Martynas
atomgraph.com


--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [xsl] JSON to XML using XSLT 3.0 representation, Martynas Jusevičius martynas@atomgraph.com <=