xpath.js
An xpath module for node, written in pure javascript.
Originally written by Cameron McCormack (blog).
Prepared as a node module by Yaron Naveh (blog).
Install
Install with npm:
npm install xpath.js
xpath.js is xml engine agnostic but I recommend to use xmldom:
npm install xmldom
Your first xpath:
var select = dom = DOMParser var xml = "<book><title>Harry Potter</title></book>" var doc = var nodes = console console
-->
title: Harry Potter
Node: <title>Harry Potter</title>
Get text values directly
var xml = "<book><title>Harry Potter</title></book>" var doc = var title = 0data console
-->
Harry Potter
Namespaces
var xml = "<book><title xmlns='myns'>Harry Potter</title></book>" var doc = var node = 0 console
-->
myns
Attributes
var xml = "<book author='J. K. Rowling'><title>Harry Potter</title></book>" var doc = var author = 0value console
-->
J. K. Rowling