Library to complement libxmljs and especially make namespaces easier to deal with.

@dreptin dreptin authored on 30 Apr 2021
src refactor: removed the files with the old count, find and setNamespace functions 2 years ago
test test: adapted tests to the new object-oriented pattern 2 years ago
.babelrc chore: switched to babel parser to make eslint support ES6 classes better 2 years ago
.editorconfig Initial commit 2 years ago
.eslintrc.json chore: switched to babel parser to make eslint support ES6 classes better 2 years ago
.gitignore Initial commit 2 years ago
LICENSE Initial commit 2 years ago
README.md docs: modified the example code in README.md and added a global description to the Document class 2 years ago
index.js docs: modified the example code in README.md and added a global description to the Document class 2 years ago
package-lock.json chore: switched to babel parser to make eslint support ES6 classes better 2 years ago
package.json chore: switched to babel parser to make eslint support ES6 classes better 2 years ago
README.md

libxmljs-extra

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"