Socket
Socket
Sign inDemoInstall

xpath

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.5 to 0.0.6

2

package.json
{
"name": "xpath",
"version": "0.0.5",
"version": "0.0.6",
"description": "DOM 3 Xpath implemention and helper for node.js.",

@@ -5,0 +5,0 @@ "engines": {

@@ -47,3 +47,3 @@ ## xpath

`````javascript
var xml = "<book><title xmlns='myns'>Harry Potter</title></book>"
var xml = "<book><title xmlns='myns'>Harry Potter</title></book>"
var doc = new dom().parseFromString(xml)

@@ -56,3 +56,13 @@ var node = xpath.select("//*[local-name(.)='title' and namespace-uri(.)='myns/']", doc)[0]

myns
## Namespaces with easy mappings
`````javascript
var xml = "<book xmlns:bookml='http://example.com/book'><bookml:title>Harry Potter</bookml:title></book>"
var select = xpath.useNamespaces({"bookml": "http://example.com/book"});
console.log(select('//bookml:title/text()', doc)[0].nodeValue));
`````
-->
Harry Potter
## Attributes

@@ -62,3 +72,3 @@ `````javascript

var doc = new dom().parseFromString(xml)
var author = xpath.select1(doc, "/book/@author").value
var author = xpath.select1("/book/@author", doc).value
console.log(author)

@@ -65,0 +75,0 @@ `````

var xpath = require('./xpath.js')
, dom = require('xmldom').DOMParser
, assert = require('assert')
, assert = require('assert');

@@ -72,2 +72,34 @@ module.exports = {

'select xpath with namespaces, using a resolver': function (test) {
var xml = '<book xmlns:testns="http://example.com/test"><testns:title>Harry Potter</testns:title><testns:field testns:type="author">JKR</testns:field></book>';
var doc = new dom().parseFromString(xml);
var resolver = {
mappings: {
'testns': 'http://example.com/test'
},
lookupNamespaceURI: function(prefix) {
return this.mappings[prefix];
}
}
var nodes = xpath.selectWithResolver('//testns:title/text()', doc, resolver);
assert.equal('Harry Potter', xpath.selectWithResolver('//testns:title/text()', doc, resolver)[0].nodeValue);
assert.equal('JKR', xpath.selectWithResolver('//testns:field[@testns:type="author"]/text()', doc, resolver)[0].nodeValue);
test.done();
},
'select xpath with namespaces, using namespace mappings': function (test) {
var xml = '<book xmlns:testns="http://example.com/test"><testns:title>Harry Potter</testns:title><testns:field testns:type="author">JKR</testns:field></book>';
var doc = new dom().parseFromString(xml);
var select = xpath.useNamespaces({'testns': 'http://example.com/test'});
assert.equal('Harry Potter', select('//testns:title/text()', doc)[0].nodeValue);
assert.equal('JKR', select('//testns:field[@testns:type="author"]/text()', doc)[0].nodeValue);
test.done();
},
'select attribute': function (test) {

@@ -74,0 +106,0 @@ var xml = '<author name="J. K. Rowling"></author>';

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc