each

each( xpath=nil )
Instance Public methods

Iterates through all of the child Elements, optionally filtering them by a given XPath

xpath

optional. If supplied, this is a String XPath, and is used to filter the children, so that only matching children are yielded. Note that XPaths are automatically filtered for Elements, so that non-Element children will not be yielded

doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
doc.root.elements.each {|e|p e}       #-> Yields b, c, d, b, c, d elements
doc.root.elements.each('b') {|e|p e}  #-> Yields b, b elements
doc.root.elements.each('child::node()')  {|e|p e}
#-> Yields <b/>, <c/>, <d/>, <b/>, <c/>, <d/>
XPath.each(doc.root, 'child::node()', &block)
#-> Yields <b/>, <c/>, <d/>, sean, <b/>, <c/>, <d/>
doc_ruby_on_rails
2015-05-06 13:19:56
Comments
Leave a Comment

Please login to continue.