diff --git a/README.md b/README.md index 953f8a2..c64c951 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ Library of functions to complement [libxmljs](https://github.com/libxmljs/libxmljs). ```JS -const libxmljs = require('libxmljs'); -const extras = require('libxmljs-extra'); +const { Document } = require('libxmljs-extra'); const xml = ` @@ -16,50 +15,14 @@ `; -const xmlDoc = libxmljs.parseXml(xml); +const xmlDoc = new Document(xml); // Sets the global namespace of the document -extras.setNamespace(xmlDoc, 'namespace', 'http://www.my-namespace.org/'); +xmlDoc.setNamespace('namespace', 'http://www.my-namespace.org/'); -const grandchildren = extras.find(xmlDoc, '//grandchild'); +const grandchildren = xmlDoc.find('//grandchild'); grandchildren.forEach((grandchild) => console.log(grandchild.text())); // Prints "Hello\nWorld" -console.log(extras.count(xmlDoc, '//grandchild')); // Prints "2" +console.log(xmlDoc.count('//grandchild')); // Prints "2" ``` - -## Docs - - -### count(xmlDoc, xpath) ->Counts the amount of results of the provided XPath. - ->**args** -*xmlDoc* The instance of `Document` representating the XML document. -*xpath* The XPath to count in `xmlDoc`. - ->**returns** -The amount of results. - - -### find(xmlDoc, xpath) ->Finds the result of the provided XPath. - ->**args** -*xmlDoc* The instance of `Document` representating the XML document. -*xpath* The XPath to get in `xmlDoc`. - ->**returns** -The found `Element` or `Element`s. - - -### setNamespace(xmlDoc, alias, url) ->Sets the namespace to use for the specified `Document`. - ->**args** -*xmlDoc* The `Document` instance to set the namespace of. -*alias* The namespace alias. -*url* The namespace URL. - ->**returns** -void diff --git a/index.js b/index.js index c70c4e3..763dcba 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,10 @@ const Document = require('./src/Document'); module.exports = { + /** + * A copy of the Document class from `libxmljs` with extras methods + * and existing ones modified. + */ Document, /**