Easy XML To JSON Converter - manta_xml

File Size: 58.2 KB
Views Total: 5171
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Easy XML To JSON Converter - manta_xml

manta_xml is a small XML parser & reader library which can be used to convert XML into JSON format.

It also provides a find method that allows the user to search your XML data by a query object.

How to use it:

1. To create a XML To JSON convert, load the JavaScript manta_xml.var.js after jQuery.

<script src="/path/to/jquery.slim.min.js"></script>
<script src="/path/to/manta_xml.var.js"></script>

2. Create a textarea to hold the XML data.

<textarea id="inputXML">
  XML Data Here

3. Create another textarea to hold the JSON output.

<textarea id="json">
  JSON Data Here

4. Create a button to perform the conversion.

<button id="convert" type="button">Convert</button>

5. The jQuery script to activate the XML To JSON converter.

$("#convert").on("click", function() {
  var xml = $("#inputXML").val();

6. Parse your XML data.

const parser = xmlParser("YOUR XML DATA HERE");

7. Seach through your XML data using the find method.

parser.find({attrs: {attribute: 'value'}});
// or
results = parser.find(function(node) { return(node.attrs.id && node.attrs.id === '1234'); });

8. Edit your XML data.

var document  = xmlParser("<node id='23'>inner text</node>"),
    node      = document.find({attrs: {id: '23'}})[0];

node.setAttr("id", "24");
node.setAttr("name", "Manta");

var xml = document.toXML();
// or a formatted xml
var xml = document.toXML(true);

This awesome jQuery plugin is developed by Heavyblade. For more Advanced Usages, please check the demo page or visit the official website.