This site uses cookies. By continuing, your consent is assumed. Learn more

125.1fm shares

Non validating dom parser is undefined

opinion

Ever had the urge to parse XML? And wanted to access the data in some sane, easy way? Don't want to compile a C parser, for whatever reason?

Now the above code does...

Then xml2js is what you're looking for! It supports bi-directional conversion.

Uses sax-js and xmlbuilder-js. Simplest way to install xml2js is to use npmjust npm install xml2js which will download xml2js and all dependencies.

No extensive tutorials required because you are a smart developer! The task of parsing XML should be an easy one, so let's make it so! Can't get easier than this, right? This works starting with xml2js 0. With CoffeeScript it looks like this:. Non validating dom parser is undefined you need some special options, fear not, xml2js supports a number of options see belowyou can specify these as second argument:.

That's right, if you have been using xml-simple or a home-grown wrapper, this was added in 0. You can also use xml2js from CoffeeScriptfurther reducing the clutter:. But what happens if you forget the new keyword to create a new Parser? In the middle of a nightly coding session, it might get lost, after all. Worry not, we got you covered! Just wrap the result object in a call to JSON.

You might wonder why, using console.

News feed