Skip to main content

Parse XML into JavaScript objects

xml2js utility ported to Deno from xml-js library.

saxes (it’s version for Deno) library is used to parse XML.

See js2xml to convert objects back to XML.

Usage example

import { xml2js } from "https://deno.land/x/xml2js@1.0.0/mod.ts";

const xml = `
<foo>
    <bar>41</bar>
    <baz boo="42">
        <baa><![CDATA[43]]></baa>
    </baz>
</foo>
`

const obj = xml2js(xml, {
  compact: true,
});

console.log(JSON.stringify(obj, null, 4));

Output:

{
    "foo": {
        "bar": {
            "_text": "41"
        },
        "baz": {
            "_attributes": {
                "boo": "42"
            },
            "baa": {
                "_cdata": "43"
            }
        }
    }
}

License information

This project is released under the Apache License 2.0.