From: 7stud -- Date: 2009-03-10T18:42:58+09:00 Subject: Re: how to get all attributes in an element Naresh Ramaswamy wrote: > hi, > > I am using REXML > > I want to get all the attributes under an element. Just imagine that I > know the element name but not the attribute names. > > say and so on as many attributes > that can be. > > I need to get all the attributes under the element. How shall I do it. > > I looked into REXML doc that provides > "doc.root.attributes.each {|name, value| puts name+" => "+value }" > > But I am able to use this only on root element, and does not work on > child or subchild elements. > > Please let me know how can I do that. > > Regards, > Naresh require 'rexml/document' include REXML xml = < Tove Jani Reminder Don't forget me this weekend! ENDSTRING doc = Document.new xml el_name = "body" matching_elements = XPath.match(doc, "//#{el_name}") matching_elements.each do |el| attrs = el.attributes attrs.each_key do |key| puts attrs[key] end end --output:-- x y -- Posted via http://www.ruby-forum.com/.