From: "Sebastian (syepes)" Date: 2008-12-11T19:26:29+09:00 Subject: Re: Problem parseing a XML - PullParser Bob Hutchison wrote: > Hi, > > On 10-Dec-08, at 8:35 AM, Sebastian (syepes) wrote: > >> Mmm, so is there a way to "parse* each line of the XML independently, >> and is it posible with the PullParser library? > > > Having written a pull parser, I'd have to say: No. > > The parser is going to be looking for 'events', and it is going to > want to deal with well-formedness issues if it is an actual xml parser. > > What are you trying to do, maybe that's a better place to start. > > Cheers, > Bob > > ---- > Bob Hutchison > Recursive Design Inc. > http://www.recursive.ca/ > weblog: http://www.recursive.ca/hutch Ok, this is the problem i am trying to solve: I need to parse a XML that comes from the stdout of a unix program, the program sends a xml* stream when it detects a change and the IO.popen stays open until the next change. The real problem is that the function: ex_listener, processes the XML "line by line" because i can't detect a EOF from the IO.popen and it will always be waiting (open) for the next change "xml stream". I have tried using "lines = ios.readlines", but it does not work because there's no EOF, is there some other way of doing this? I would appreciate any suggestions on how to solve this problem. *xml: Sent when a change is detected --- Testing:service Critical Normal Ruby --------- UNIX_PROG = "/bin/xml_stream" def ex_connect ios = IO.popen(UNIX_PROG,"w+") ios.sync = true line = ios.gets if line =~ /xml/ puts "INF: Connected OK (XML)" ios.puts "" return ios else puts "ERR: Cannot connect" exit 1 end end def ex_listener(ios) while (line = ios.gets) line.chomp! if line =~ /<\/Events>/ puts "INF: END of program" exit 0 end puts "INF: #{line} - #{line.size}" *parse_line_of_xml(line)* end end ios = ex_connect ex_listener(ios) # Processes the XML stream --------- Regards, -- Posted via http://www.ruby-forum.com/.