Robert said:
this is the criteria:
node=rexml_element.find_first_recursive {|node|
node.attributes["again"]=="yes"}
That's easy
doc.elements.each('//[@again="yes"]') do |node|
# any node that has attribute again with value yes
end
And I am pretty sure that this is faster than your approach. What does
your program do? With more context we can come up with further
suggestions.
Kind regards
robert
I'm not sure if that will works, i have a xml file with this
structure(and it must be like this, the following example is a simple
sample of the original):
<root>
<new_section>
<pages>
<page again="yes">page1</page>
<page again="no">page2</page>
<page againe=yes"">page3
<pages>
<page again="no">page4<page>
<page again="yes">
<pages>....and so on
</pages>
</page>
</pages>
</new_section>
<new_section>
</root>
I have a recursive function to find all 'page' nodes with attribute
'again' 'yes but i need to start the searc from the beging of the file
or from the current node and the display all subnodes with 'yes'; after
the all nodes was founded then i need to search them again from the
begining of the file; its something like this:
def find(xml_file)
node=xml_file.find_first_recursive {|node|
node.attributes["again"]=="yes"}
if not(node==nil)
then
puts node.text
find(xml_file.elements[node])
else
find(xml_file.elements["//"])
end
end
In this example the find function is an endless loop, somewhere i must
put a return, but i need something like that and when my file is big
(~900) i wait ~10 seconds for the command (but not always - only when
i'm starting to search from the beging of the file):
node=xml_file.find_first_recursive {|node|
node.attributes["again"]=="yes"}
Many thanks for your help Robert.