Skip to content

mattlag/XMLtoJSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XMLtoJSON

I know there are probably 13.5 Million of these already, but I wanted to do one myself, okay?

resulting xml_tag data structure

{
    name : 'xml_tag_name',
    attributes : {
        'xml_attribute_name1' : 'XML Attribute value1',
        'xml_attribute_name2' : 'XML Attribute value2',
        'xml_attribute_name3' : 'XML Attribute value3',
        ...
    },
    content : [
        { xml_tags },
        { xml_tags },
        ...,
        'text content'
    ]
}

A proper JavaScript SyntaxError will be thrown if the XML is not properly formatted.

Things to consider

XMLtoJSON is really focused on data, and not so much the metadata. So I did this:

  • All comments are ignored <!-- stuff like this -->
  • All declarations are ignored, stuff like <?xml version="1.0" encoding="UTF-8"?>
  • All CDATA sections are ignored, stuff like <![CDATA[<greeting>Hello, world!</greeting>]]>
  • Newline and Tab characters, like \r \n \t, are blindly removed from everywhere

License & Copyright

Copyright © 2024 Matthew LaGrandeur

Released under GPL 3.0

Author

Matthew LaGrandeur's picture
Matthew LaGrandeur
matt[at]mattlag[dot]com