Library to complement libxmljs and especially make namespaces easier to deal with.
src | 2 years ago | ||
test | 2 years ago | ||
.babelrc | 2 years ago | ||
.editorconfig | 2 years ago | ||
.eslintrc.json | 2 years ago | ||
.gitignore | 2 years ago | ||
LICENSE | 2 years ago | ||
README.md | 2 years ago | ||
index.js | 2 years ago | ||
package-lock.json | 2 years ago | ||
package.json | 2 years ago |
Library of functions to complement libxmljs.
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"