S
Sebastian (syepes)
Hi all,
I need to parse a XML file "line by line" because of a application
limitation, so i am trying to build a Stream/Pull xml parser with the
rexml library, but i can't get it to work..
- Anyone knows what can be causing this error? -> Missing end tag for
''
- This error even happens with a simple xml like this one:
psudo_xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<SChange>
</SChange>
EOF
Error:
----------
DBG: event_type: text
TXT Normal
DBG: event_type: end_element
END Mode
/opt/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:330:in `pull':
Missing end tag for '' (got "SChange") (REXML:arseException)
Line:
Position:
Last 80 unconsumed characters:
from /opt/local/lib/ruby/1.8/rexml/parsers/pullparser.rb:68:in `pull'
from text2.rb:13:in `parse'
from text2.rb:32:in `line_process'
from text2.rb:47
Ruby code
----------
require "stringio"
require 'rexml/parsers/pullparser'
class BaseParser
def initialize
@parser = nil
end
def parse(raw_xml)
@parser = REXML:arsers:ullParser.new(raw_xml)
while @parser.has_next?
pull_event = @parser.pull
puts "DBG: event_type: #{pull_event.event_type}"
if pull_event.error?
puts "\tERR #{pull_event[0]} - #{pull_event[0]}"
elsif pull_event.start_element?
puts "\tSTART #{pull_event[0]}"
elsif pull_event.end_element?
puts "\tEND #{pull_event[0]}"
elsif pull_event.text?
puts "\tTXT #{pull_event[0]}"
end
end
end
end
def line_process(ios,myparser)
while (line = ios.gets)
line.chomp!
myparser.parse(line)
end
end
psudo_xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<SChange>
<Service>Testing:service</Service>
<Status>Critical</Status>
<Mode>Normal</Mode>
</SChange>
EOF
psudo_xml_io = StringIO.new(psudo_xml)
line_process(psudo_xml_io,BaseParser.new)
I need to parse a XML file "line by line" because of a application
limitation, so i am trying to build a Stream/Pull xml parser with the
rexml library, but i can't get it to work..
- Anyone knows what can be causing this error? -> Missing end tag for
''
- This error even happens with a simple xml like this one:
psudo_xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<SChange>
</SChange>
EOF
Error:
----------
DBG: event_type: text
TXT Normal
DBG: event_type: end_element
END Mode
/opt/local/lib/ruby/1.8/rexml/parsers/baseparser.rb:330:in `pull':
Missing end tag for '' (got "SChange") (REXML:arseException)
Line:
Position:
Last 80 unconsumed characters:
from /opt/local/lib/ruby/1.8/rexml/parsers/pullparser.rb:68:in `pull'
from text2.rb:13:in `parse'
from text2.rb:32:in `line_process'
from text2.rb:47
Ruby code
----------
require "stringio"
require 'rexml/parsers/pullparser'
class BaseParser
def initialize
@parser = nil
end
def parse(raw_xml)
@parser = REXML:arsers:ullParser.new(raw_xml)
while @parser.has_next?
pull_event = @parser.pull
puts "DBG: event_type: #{pull_event.event_type}"
if pull_event.error?
puts "\tERR #{pull_event[0]} - #{pull_event[0]}"
elsif pull_event.start_element?
puts "\tSTART #{pull_event[0]}"
elsif pull_event.end_element?
puts "\tEND #{pull_event[0]}"
elsif pull_event.text?
puts "\tTXT #{pull_event[0]}"
end
end
end
end
def line_process(ios,myparser)
while (line = ios.gets)
line.chomp!
myparser.parse(line)
end
end
psudo_xml = <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<SChange>
<Service>Testing:service</Service>
<Status>Critical</Status>
<Mode>Normal</Mode>
</SChange>
EOF
psudo_xml_io = StringIO.new(psudo_xml)
line_process(psudo_xml_io,BaseParser.new)