Newer
Older
libxmljs-extra / 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"