Skip to content

Commit

Permalink
Merge branch 'nsxpath'
Browse files Browse the repository at this point in the history
  • Loading branch information
ncb000gt committed Feb 21, 2013
2 parents 1f11c30 + a30cd8d commit 51b2020
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,39 @@ module.exports.nested = function(assert) {

assert.done();
};

module.exports.xmlns = function(assert) {
var str = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><div>BACON</div><div>ROCKS</div><p>WUT?</p></body></html>';
var doc = libxml.parseXmlString(str);
//throw because we don't specify the url
//assert.throws(function() {
//doc.find('//xmlns:div');
//});
var divs = doc.find('//xmlns:div', 'http://www.w3.org/1999/xhtml');
assert.equal(divs.length, 2);

var div = doc.get('//xmlns:div', 'http://www.w3.org/1999/xhtml');
var exp = doc.root().child(2).child(0);
assert.ok(div != null);
assert.ok(exp != null);
assert.equal(div.toString(), exp.toString());
assert.done();
}

module.exports.custom_ns = function(assert) {
var str = '<html xmlns:bacon="http://www.example.com/fake/uri"><head></head><body><div>BACON</div><div>ROCKS</div><p>WUT?</p></body></html>';
var doc = libxml.parseXmlString(str);
//throw because we don't specify the url
//assert.throws(function() {
//doc.find('//xmlns:div');
//});
var divs = doc.find('//bacon:div', 'http://www.example.com/fake/uri');
assert.equal(divs.length, 2);

var div = doc.get('//bacon:div', 'http://www.example.com/fake/uri');
var exp = doc.root().child(2).child(0);
assert.ok(div != null);
assert.ok(exp != null);
assert.equal(div.toString(), exp.toString());
assert.done();
}

0 comments on commit 51b2020

Please sign in to comment.