Dalbir Singh
Posted on January 29, 2020
Today I was asked to provide technical consultation for a customer involving the generation of an XML document.
These days we developers play with JSON, but it is worth noting XML played some influence with JSON’s global adoption. You’ll often hear a lot talk about data models, sequences, markup and so forth in the JSON community – lessons that were learned from putting together XML standards.
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
</book>
</catalog>
It’s been a while since I authored an XML document – I was reminded how the data structures are easier to read and understand. That’s not to say JSON isn’t readable, its just that with XML and it’s SGML derivatives the model is easier to comprehend, initially at least.
When I started thinking about how to parse XML documents again, It was then I was reminded why JSON is loved. While XML presents the data in an immediately readable format, JSON presents the data in an easily digestible format for your application code. No need, for complex XPath queries, just bind it to your internal model and your done!
If JSON is the preferred choice for data transfer within applications, does XML have anything left to offer?
Yes – documents…
XSLT
XSLT (eXtensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to other formats, such as PDF, PostScript and PNG.
Example of XML/XSLT: In the image above you can see an example of XML and XSLT working together. The XSLT file uses XPath queries to lift information out of the XML document and render the content using templates. The output is shown below.
XML still works best for documents. Documents by their nature have a form of structure that is represented better through XML.
Combine XML with XSLT and you’re able to perform impressive transformations with nothing more than .xml and .xsl files.
So, Is XML Dead?
Not yet – XML still has its place for document-based structures. Also many financial institutions rely heavily on XML based formats for transferring information between enterprise systems that were built in the 2000s.
It’s well known financial enterprises such as Banks are reluctant to ‘upgrade’ their systems unless they really need to. So XML may not be the new kid on the block, and relegated to more mundane infrastructure but it’s still alive and kicking. 🤓
What about you? - Do you still use XML day to day?
Posted on January 29, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.