Wednesday 13 April 2022

XML Stylesheet Pretty Printer for any XML File

(very old draft) XML files are hard to read. This is made worse when spaces and newlines are removed. To make them more readable I have made a simple stylesheet that will indent the XML and format it so it is easy to read. The XML stylesheet is very simple: To get the stylesheet, highlight it, copy it and paste it into an empty file called pcSimpleReformat.xsl (you can change the name it you like). To apply the stylesheet you need an XSL[T] processor such as xsltproc:
xsltproc pcSimpleReformat.xsl someXMLFile.xml
The output will be the easy-to-read version of the the XML file. A slightly more complicated version follows complete with comments so you can see how it works: This is the small version. It outputs will formatted text but it is a little verbose. To download, select the XML code, copy and paste it into a file called pcReformatSimple.xsl http://www.w3.org/1999/XSL/Transform"> To apply it you would use a command like this: xsltproc pcReformatSimple.xsl someInputXMLFile.xml To test that it is working we can apply it twice and compare the output at each stage. If it is working then the intermediate stage should be identical to the final stage. ie. it will reformat an xml file the xml is reformatted xsltproc pcReformat.xsl q.rng > q1.rng diff q.rng q1.rng less q.rng http://www.w3.org/1999/XSL/Transform">

No comments:

Post a Comment

Please use family friendly language.