Library to complement libxmljs and especially make namespaces easier to deal with.
| src | 4 years ago | ||
| test | 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 of functions to complement libxmljs.
const libxmljs = require('libxmljs');
const extras = 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 = libxmljs.parseXml(xml);
// Sets the global namespace of the document
extras.setNamespace(xmlDoc, 'namespace', 'http://www.my-namespace.org/');
const grandchildren = extras.find(xmlDoc, '//grandchild');
grandchildren.forEach((grandchild) => console.log(grandchild.text())); // Prints "Hello\nWorld"
console.log(extras.count(xmlDoc, '//grandchildren')); // Prints "2"
Counts the amount of results of the provided XPath.
args
xmlDoc The instance ofDocumentrepresentating the XML document.
xpath The XPath to count inxmlDoc.returns
The amount of results.
Finds the result of the provided XPath.
args
xmlDoc The instance ofDocumentrepresentating the XML document.
xpath The XPath to get inxmlDoc.returns
The foundElementorElements.
Sets the namespace to use for the specified
Document.args
xmlDoc TheDocumentinstance to set the namespace of.
alias The namespace alias.
url The namespace URL.returns
void