G
Gavin Kistner
In XPath, "//" is an abbreviation for the "descendant-or-self"
selector. My understanding (and Microsoft's XPath implementation) of
this selector means that the following code should select the bar
element as well as the descendants.
[Sliver:~/Desktop] gkistner$ cat tmp.rb
xml = <<ENDXML
<foo id="foo">
<bar id="bar">
<jim id="jim" />
<jam id="jam" />
<bork><whee id="whee" /></bork>
</bar>
</foo>
ENDXML
require 'rexml/document'
include REXML
bar = XPath.first( Document.new( xml ), '//bar' )
bar.each_element( './/[@id]' ){ |element_with_id|
puts element_with_id
}
[Sliver:~/Desktop] gkistner$ ruby -v tmp.rb
ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.2]
<jim id='jim'/>
<jam id='jam'/>
<whee id='whee'/>
selector. My understanding (and Microsoft's XPath implementation) of
this selector means that the following code should select the bar
element as well as the descendants.
[Sliver:~/Desktop] gkistner$ cat tmp.rb
xml = <<ENDXML
<foo id="foo">
<bar id="bar">
<jim id="jim" />
<jam id="jam" />
<bork><whee id="whee" /></bork>
</bar>
</foo>
ENDXML
require 'rexml/document'
include REXML
bar = XPath.first( Document.new( xml ), '//bar' )
bar.each_element( './/[@id]' ){ |element_with_id|
puts element_with_id
}
[Sliver:~/Desktop] gkistner$ ruby -v tmp.rb
ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.2]
<jim id='jim'/>
<jam id='jam'/>
<whee id='whee'/>