Powerful XML parser to deal with Inspire and OGC standards
npm install -g inspire-parser
cat metadata.xml | inspire2json
npm install inspire-parser
const parse = require('inspire-parser').parse;
const xmlString = `<csw:Record xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/">
<dc:title>Prochains passages temps réel du réseau TCL</dc:title>
<dc:subject>Réseaux de transport</dc:subject>
<dc:subject>Services d'utilité publique et services publics</dc:subject>
</csw:Record>`;
parse(xmlString, (err, result) => {
console.log(result.type); // print parsed element type: Record
console.log(JSON.stringify(result.body, true, 4)); // Print parsed result below
});
Result (very basic example):
{
"title": "Prochains passages temps réel du réseau TCL",
"subject": [
"Réseaux de transport",
"Services d'utilité publique et services publics"
]
}
const fs = require('fs');
const Parser = require('inspire-parser').Parser;
const parser = new Parser();
const xmlStream = fs.createReadStream(pathToXmlFile);
xmlStream.pipe(parser).once('result', result => {
console.log(result.type); // print parsed element type
console.log(JSON.stringify(result.body, true, 4)); // Print parsed result in JSON
});