Xml Schema Report

SEPA is coming and people have been asking how can I check if this pain file is valid. In this post I will demonstrate how we can transform an XML file to HTML and include any XSD validation exceptions into the mix.

The technique described here is general purpose i.e. its not limited to PAIN.008 and PAIN.002 files, these XML files just seem to be in fashion.
Internet Explorer has a clever trick up its sleeve when it comes to rendering XML files. It basically converts them on the fly using an XSLT style-sheet called defaultss.xsl. This style-sheet is packaged inside the MSXML3.dll file e.g. res://msxml3.dll/xml/defaultss.xsl will display the style sheet in Internet Explorer. The flavour of XSL contained in this stylesheet is based on a working draft but a bit of googling will find a version based on an XSL recommendation.

With some minor modification I’ve leveraged this stylesheet to render the XML file along with the XSD validation issues. The file was a bit long to include in the post so I’ve made it available as a gist.
If you look at the XSL file you can see I’ve added a couple of new templates to match four new processing instructions.

  1. schemaSummary
  2. schemaValid
  3. schemaInvalid
  4. error

This new processing instructions are added to the SAX event stream by a specialised XMLFilter implementation.

And here is a quick JUnit test to run transform a sample file

I downloaded a sample PAIN.008 file from the ISO20022 website and added one or two typo’s and ran it through the test case. The results looks like

Tagged with: , , ,
Posted in Sax, Uncategorized, Xml

Leave a Reply

Your email address will not be published.