There are some debates about declining use of XML and rising use of JSON. Some people love XML, some people love JSON. I love SAX: assuming SAX serializer/deserializers exist, anything can be treated as XML.
For example, you can write XSLT stylesheets transforming JSON: JSON SAX deserializer was already created by me in my previous article “How to Convert JSON to XML using ANTLR” and JSON SAX serializer is fairly easy to write. Once you have all that, you can transform JSON using XSLT:
expand source
expand source
Java code to perform the transformation:
expand source
This is simple SAX pipeline, coded in reverse order, w/ SAX event flow like:
JsonSaxReader->TransformerHandler->ValidatorHandler->JsonSaxWriter. Notice, XSD validation is purely optional, it is just to double-check output of XSLT.





Leave a Reply