Break from a loop which is run on a xml

how do i loop through a xml and break when i find the node with a
specific value..really struggling to break out of a xml loop..most of
the iterators just loop but cannot be break - ed

please help me with this

for e.g.

this is d code where i find the files in a dir & check d earlier time
stamp for each file which is saved in a xml & do a comparison for each

Find.find('./'){|path|
  if path != './abcd.rb'
    if ! File::directory? ( path )
    modtime = File.mtime(path)
    xmldoc.elements.each("course/file"){ |element|
  oldtime = Time.parse(element.attributes["modified"])
  if modtime > oldtime
        $changed = "yes"
  break
  else
  $changed = "no"
  end
  }
      newfile = course.add_element 'file', {'version'=>'2.0',
'modified'=> modtime, 'download'=>$changed}
      newfile.text = path[2,path.length]
  end
  end
}

this is the sample xml..

<course name='' uniqueID='' serverURL='' >
<file version='1.0' modified='2011-11-30 16:37:23 +0530' download='no'>
xyzw.pdf
</file>
<file version='1.0' modified='2011-11-07 02:30:01 +0530' download='no'>
content/banner/t1-st_1.swf
</file>
<file version='1.0' modified='2011-11-07 02:30:01 +0530' download='no'>
content/t1/st_1/page1.swf
</file>
<file version='1.0' modified='2011-11-07 02:30:02 +0530' download='no'>
content/t1/st_2/page1.swf
</file>
<file version='1.0' modified='2011-11-07 02:30:02 +0530' download='no'>
content/t1/st_2/page2.swf
</file>
<file version='1.0' modified='2011-11-07 02:30:03 +0530' download='no'>
content/t1/st_2/page3.swf
</file>
</course>

···

--
Posted via http://www.ruby-forum.com/.

hi Mythpills,

  try to reduce your code to an executable snippet and then post that -
what you've posted above cannot be executed as there are undefined
variables.

  - j

···

--
Posted via http://www.ruby-forum.com/.

Use a proper XPath expression. Other than that I second what Jake said.

Kind regards

robert

···

On Thu, Dec 1, 2011 at 7:02 AM, mythpills P. <pillay.mithun@gmail.com> wrote:

how do i loop through a xml and break when i find the node with a
specific value..really struggling to break out of a xml loop..most of
the iterators just loop but cannot be break - ed

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

sorry guys..its company code cannot make it public.neways i figured out
a way out by using arrays and running a for loop over it..works just the
way i wanted

wish there was a obvious way to do things in Ruby..its concise but it is
cumbersome

···

--
Posted via http://www.ruby-forum.com/.

sorry guys..its company code cannot make it public.

Then strip it down / change it to a simple case which shows the
problem you are trying to solve.
http://sscce.org/

neways i figured out
a way out by using arrays and running a for loop over it..works just the
way i wanted

Chances are that using doc#at_xpath with Nokogiri is simpler than what
you built.

wish there was a obvious way to do things in Ruby..its concise but it is
cumbersome

I think there is an obvious way (using XPath to select exactly the
nodes you want) but without you showing a proper example we cannot
show it to you. I find it a tad unfair to blame Ruby when you are not
providing proper information.

Kind regards

robert

···

On Wed, Dec 7, 2011 at 7:59 AM, mythpills P. <pillay.mithun@gmail.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/