Robert Klemme
3/30/2008 9:45:00 PM
On 30.03.2008 22:21, Bu Mihai wrote:
> Robert Klemme wrote:
>> On 30.03.2008 20:23, Bu Mihai wrote:
>>> 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.
>
> 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';
You can use the XPath from the root and I believe also from a
particulara node.
> after
> the all nodes was founded then i need to search them again from the
> begining of the file;
When I asked what your program does, I really meant: Can you explain in
non technical words what this program is supposed to do? Since you seem
to traverse over the same nodes over and over again I have the strong
feeling that there is a better alternative - but for that we need to
know the purpose of the program.
> Many thanks for your help Robert.
You're welcome.
Kind regards
robert