Javascript: Parsing XML and JSON

This article today is about parsing, something I do a lot when designing Cloud Portal in VRA 7. Most of the time I store lists of elements as JSON or XML resource files, those files are easily understood by admins and it prevent them to change to many settings in VRA and with the risk of breaking the cloud platform. Working with files allows versioning and it much easier to add or remove entries, but it require some development.

Let see an example of XML file used to load a list of elements in VMware vRealize Automation:

How it work: The XML file is stored in vRO (vRealize Orchestrator), a vRO action is created to parse the XML file and return a list of network’s name. Finally this action in linked to the « Network list » field in the deployment form.

Let’s talk about parsing now, and how to return a specific value or a list of elements using xml and json in Javascript. For that I am using two parsers common in Javascript:

Parsing XML – with Mozilla E4X

The file (parsing.xml) we are going to parse has been created specifically for this article:

Json is much more complicated to parse in Javascript, however if you want to write new values or insert nodes in those kind of resource files, you might choose JSON because it’s all about « push » to insert in a JSON array and « = » to assign new values.

Next time we will see how to use parser to create dynamic list in vRealize Automation and vRealize Orchestrator.