From: Sean Russell Date: 2001-11-18T03:47:52+09:00 Subject: [ruby-talk:25719] Re: REXML: node.type, .parent, .name Tobias Reif wrote: > is something like the following possible in REXML (in a convenient way?)? > > > node.children.each do |node| > > if node.type == 'element' > > parent_name = node.parent.name > self_name = node.name Yes, but I don't know why you'd want to. element.elements.each do |elem_child| # elem_child is guaranteed to be an Element parent_name = elem_child.parent.name name = elem_child.name end > If not, these methods would be a useful addition to REXML for me: These methods are described both in the API docs and the tutorial. > node.type > node.parent > node.child > node.name If you really want to check arbitrary children types, do: parent.each do |child| case child.type when Element puts "Element" when Text puts "Text" when CData puts "CData" when Comment puts "Comment" end puts child.parent.type end If you check the inheritance tree (in the documentation) you'll see a module called "Namespace". All classes that include Namespace have a "name" method. All subclasses of Child have a parent method. The documentation is really helpful if you want to find out about these methods. --- SER -----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World! Check out our new Unlimited Server. No Download or Time Limits! -----== Over 80,000 Newsgroups - 19 Different Servers! ==-----