How would you convert from XML to JSON and then back to XML?
The following tools work quite well, but aren't completely consistent:
Has anyone encountered this situation before?
How would you convert from XML to JSON and then back to XML?
The following tools work quite well, but aren't completely consistent:
Has anyone encountered this situation before?
Disclaimer: I've written fast-xml-parser
Fast XML Parser can help to convert XML to JSON and vice versa. Here is the example;
If you want to parse JSON or JS object into XML then
https://github.com/abdmob/x2js - my own library (updated URL from http://code.google.com/p/x2js/):
Online Demo on http://jsfiddle.net/abdmob/gkxucxrj/1/
A while back I wrote this tool https://bitbucket.org/surenrao/xml2json for my TV Watchlist app, hope this helps too.
These answers helped me a lot to make this function:
As long as you pass in a jquery dom/xml object: for me it was:
where content was the field I was storing my xml in.
Here' a good tool from a documented and very famous npm library that does the xml <-> js conversions very well: differently from some (maybe all) of the above proposed solutions, it converts xml comments also.
I would personally recommend this tool. It is an XML to JSON converter.
It is very lightweight and is in pure JavaScript. It needs no dependencies. You can simply add the functions to your code and use it as you wish.
It also takes the XML attributes into considerations.
Here's an online demo!