Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > rexml each_element_with_attribute question

Reply
Thread Tools

rexml each_element_with_attribute question

 
 
zerohalo
Guest
Posts: n/a
 
      08-27-2005
I'm a Ruby newbie and have been working on a script that among other
things, parses a series of XML files, searches for elements that
contain a certain attribute ('question') and then parsing through the
children of all of those elements for certain tags. Note that
'question' elements can be anywhere in the XML file - one level deep or
ten levels deep - so doing an exact path match for 'question' doesn't
work.

I thought I had found an easy way with
doc.root.each_element_with_attribute('question') and that it would
return an array of all of the 'question' elements in the whole file.
But after much frustration I finally realized that it only returns the
elements with that attribute that are at that level - it doesn't
recurse through all the children in the file to find them all. Hard to
believe that there's not an option to have it recurse through all the
children, but maybe I haven't found it. The documentation on rexml
isn't that extensive and I had a hard time understanding some things
(of course that's also due to the the fact that I'm a n00b).

I've tried using XPath.match('question') but Xpath requires the path,
and like I said, these 'question' elements could be at any level,
depending on the XML file, so I'm not sure that that works either
(other than going through each level of the document "manually", but
that sucks).

Does anyone know of a simple way, using something like
each_element_with_attribute, to return an array of all of the elements
that match a certain attribute?

Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
REXML::Element.write is deprecated. See REXML::Formatters Phlip Ruby 0 01-15-2008 08:23 PM
rexml error - REXML::Validation Daniel Berger Ruby 2 10-12-2004 04:19 PM
Rexml xpath question Han Holl Ruby 7 03-06-2004 01:23 PM
REXML & Extended characters - newbie question Ralph Mason Ruby 2 01-13-2004 12:36 AM
soap4r 1.4.8.1 with REXML 2.7.1 - no REXML::VERSION_MAJOR Damphyr Ruby 2 07-16-2003 09:49 AM



Advertisments