rexml each_element_with_attribute question
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
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
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?
|All times are GMT. The time now is 01:32 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.