Library to complement libxmljs and especially make namespaces easier to deal with.
| docs | 4 years ago | ||
| src | 4 years ago | ||
| test | 4 years ago | ||
| .babelrc | 4 years ago | ||
| .editorconfig | 4 years ago | ||
| .eslintrc.json | 4 years ago | ||
| .gitignore | 4 years ago | ||
| LICENSE | 4 years ago | ||
| README.md | 4 years ago | ||
| index.js | 4 years ago | ||
| package-lock.json | 4 years ago | ||
| package.json | 4 years ago | ||
Library to complement libxmljs and especially make namespaces easier to deal with.
const { Document } = require('libxmljs-extra');
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.my-namespace.org/">
<child>
<grandchild>Hello</grandchild>
</child>
<child>
<grandchild>World</grandchild>
</child>
</root>`;
const xmlDoc = new Document(xml);
// Sets the global namespace of the document
xmlDoc.setNamespace('namespace', 'http://www.my-namespace.org/');
const grandchildren = xmlDoc.find('//grandchild');
grandchildren.forEach((grandchild) => console.log(grandchild.text())); // Prints "Hello\nWorld"
console.log(xmlDoc.count('//grandchild')); // Prints "2"
Check the [docs](https://gitbucket.inist.fr/istex/libxmljs-extra/tree/master/docs) directory.