Created
January 1, 2014 13:06
-
-
Save joshski/8207912 to your computer and use it in GitHub Desktop.
bug in npm 'xpath'?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
Nokogiri::HTML('<z><a /><b /><a /><b /><b /><b /><a /><c><a /><b /></c></z>').css("a + b") | |
=> [#<Nokogiri::XML::Element:0x3fdf7d0c0a34 name="b">, #<Nokogiri::XML::Element:0x3fdf7d0c0688 name="b">, #<Nokogiri::XML::Element:0x3fdf7d0c046c name="b">] | |
Nokogiri::HTML('<z><a /><b /><a /><b /><b /><b /><a /><c><a /><b /></c></z>').xpath("//a/following-sibling::*[1]/self::b") | |
=> [#<Nokogiri::XML::Element:0x3fdf7d0cc294 name="b">, #<Nokogiri::XML::Element:0x3fdf7d0cc08c name="b">, #<Nokogiri::XML::Element:0x3fdf7d0cbe70 name="b">] | |
$('<z><a /><b /><a /><b /><b /><b /><a /><c><a /><b /></c></z>').find('a + b'); | |
Object[b, b, b] | |
var xpath = require('xpath'); | |
var dom = require('xmldom').DOMParser; | |
var doc = new dom().parseFromString('<z><a /><b /><a /><b /><b /><b /><a /><c><a /><b /></c></z>'); | |
var elements = xpath.select("//a/following-sibling::*[1]/self::b", doc); | |
console.log(elements.length); | |
// => prints '1' | |
var libxmljs = require("libxmljs"); | |
var doc = libxmljs.parseXml('<z><a /><b /><a /><b /><b /><b /><a /><c><a /><b /></c></z>'); | |
var elements = doc.find("//a/following-sibling::*[1]/self::b"); | |
console.log(elements.length); | |
// => prints '3' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment