Skip to content

Instantly share code, notes, and snippets.

@pupca
Created December 2, 2010 23:57
Show Gist options
  • Save pupca/726343 to your computer and use it in GitHub Desktop.
Save pupca/726343 to your computer and use it in GitHub Desktop.
source = "<a xmlns:x='foo' xmlns:y='bar'><x:b id='1'/><y:b id='2'/></a>"
doc = Document.new source
doc.elements["/a/x:b"].attributes["id"] # -> '1'
XPath.first(doc, "/a/m:b", {"m"=>"bar"}).attributes["id"] # -> '2'
doc.elements["//x:b"].prefix # -> 'x'
doc.elements["//x:b"].namespace # -> 'foo'
XPath.first(doc, "//m:b", {"m"=>"bar"}).prefix # -> 'y'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment