From: brabuhr@... Date: 2009-07-22T20:51:32+09:00 Subject: Re: Parsing XML in Ruby On Wed, Jul 22, 2009 at 4:43 AM, Adam Lorens wrote: > Bertram Scharpf wrote: >> Hi, >> >> Am Dienstag, 21. Jul 2009, 23:39:14 +0900 schrieb Adam Giewond: >>> I'm new in this forum, so i'm be very gratefull, you won't be angry if I >>> ask some stupid question. My today work is: "Parsing XML in Ruby", XML >>> is in attachment. I've never done it, so please help me:) >> >> REXML belongs to the Ruby standard library. >> >>   http://www.xml.com/pub/a/2005/11/09/rexml-processing-xml-in-ruby.html >> >> Bertram > > ok thanks very much, I decided to use REXML, but i have problem with > this examples. Here are two small examples based on your original XML: irb(main):001:0> require 'rexml/document' => true irb(main):002:0> file = File.new('sample.xml') => # irb(main):003:0> doc = REXML::Document.new(file) => ... irb(main):004:0> root = doc.root => ... irb(main):005:0> root.each_element('//ns2:sourcingChannel') do |sC| irb(main):006:1* puts sC.elements['name'].text irb(main):007:1> end United Utilities testttttttttttt Broadbean AdCourier - NEW Monster Pracuj.pl momozozo Vanilla . . . irb(main):008:0> body = root.elements['env:Body'] => ... irb(main):009:0> acr = body.elements['ns2:getActiveChannelsResponse'] => ... irb(main):010:0> acr.elements.each do |sC| irb(main):011:1* puts sC.elements['name'].text irb(main):012:1> end United Utilities N Power mzych.com HPA gttt Vanilla FCO Lloyds TSB Tel Banking OTU . . . irb(main):013:0> root.each_element('//ns2:sourcingChannel/name') do |name| irb(main):014:1* puts name.text irb(main):015:1> end testttttttttttt Broadbean AdCourier - NEW Monster Pracuj.pl momozozo Broadbean AdCourierx Vanilla . . . I usually use something like the first way: each_element with an XPath to pull out the "record" nodes for processing.