Theoretically browserify
ing it should work as discussed at https://github.com/Leonidas-from-XIV/node-xml2js/issues/277 ("pietersv commented on Nov 2, 2017").
Quoting that:
Add the following two scripts to package.json and run them after running npm test:
"browserify": "browserify ./xml2js.js -s xml2js -o ./xml2js.js",
"minify": "cat ./xml2js.js | uglifyjs > ./xml2js.min.js"
in HTML
<script type="text/javascript" src="/path/to/xml2js.min.js"></script>
<script>
var xml = '<?xml version="1.0" encoding="UTF-8"?><note>Lorem ipsum dolor sit amet...</note>'
var obj = xml2js.parseString(xml, function(err, res) { ... })
</script>
However as at today (30.7.18) that is not working with the current version (0.4.19) as stated in the follow-up comment (by me!).
Instead I used https://www.npmjs.com/package/xml-js and browserfied it (in package.json
is:
"buildxml2js": "./node_modules/.bin/browserify ./node_modules/xml-js/dist/xml-js.js -o ./public/lib/xml-js.js")
and it works a charm. After building it as ./public/lib/xml-js.js
dir add this to the html:
<script type="text/javascript" src="/lib/xml-js.js"></script>
And then call with:
xml2json(the_xml)
and
json2xml(the_json)
Sorry this doesn't actually solve your specific question, however it provides a viable work-around.