Skip to content

A parser to convert XML to JSON built using underscore.js and DOMParser browser API.

Notifications You must be signed in to change notification settings

harsh5692/xml-to-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

xml-to-json

A parser to convert XML to JSON built using underscore.js and DOMParser browser API.

Installation

  • fork the repo
  • open file index.html in browser.
  • see your JSON in console.

How it works

  1. Loads the XML from a smaple file, which is hardcoded string for now, can use other methods to load XML as needed.
  2. Uses the DOMParser to convert string into XML object with can be processed upon.
  3. parseElement is a function which parses one element at a time. Its used in recursion to parse the entire XML object.
    • Checks if the element is a text node, returns value iff so
    • Checks for childrens and attributes, iff no return the textContent of node
    • If element has no children but some textContent, adds textContent to data.text
    • If element has attributes, adds them to data.attributes
    • for each children, parse the children using "parseElement"
    • while doing so, convert all the '-'(hyphen) to '_'(underscore)

Thank you!

About

A parser to convert XML to JSON built using underscore.js and DOMParser browser API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published