-
-
Notifications
You must be signed in to change notification settings - Fork 110
XPath Support
Ozgur Ozcitak edited this page Feb 18, 2019
·
3 revisions
XML builder implements parts of the DOM specification to allow running XPath queries against it. The DOM implementation does not currently support XML namespaces.
For example, by using the xpath
module:
var builder = require('xmlbuilder');
var xpath = require('xpath');
var doc = builder.create('book')
.ele('title')
.txt('The Book')
.doc();
var nodes = xpath.select('//title', doc); // pass the XML document to XPath
console.log(nodes[0].localName); // 'title'
console.log(nodes[0].firstChild.data); // 'The Book'
console.log(nodes[0].toString()); // <title>The Book</title>