I also like XPath for some purposes, but I think it really suffers from (IIRC) having been designed before the xml namespaces, which it only integrates very awkwardly IMO and which ruins the simplicity of XPath. Or maybe XML namespaces spoil everything they affect to some degree :)
doc = Nokogiri::XML(stream)
doc.xpath("//x:foo", {x: "http://somenamespace/"}).each ...
I always end up declaring the namespaces in a constant and passing it in, because there is no way to specify your mappings globally. It should have been something like: doc = Nokogiri::XML(stream)
doc.namespaces = {x: "http://somenamespace/"}
doc.xpath("//x:foo").each ...
or at least something functional like: doc = Nokogiri::XML(stream)
doc.using_namespaces(x: "http://somenamespace/").
xpath("//x:foo").each ...
I have seen this way of integrating namespaces and XPath in several libraries, it's not just Nokogiri.