![](http://www.gnu-darwin.org/hexley-gd-sm.png)
|
def Element.parse_stream source, listener
begin
# Get the next tag
name, closed, attrs = base_parser(source)
attrs.each { |ar| ar[1,1] = [] }
listener.tag_start name, attrs
unless closed
while true
md = source.match(/\A(\s*[^>]*>)/um)
raise ParseException.new("malformed XML: bad content", source,
self) unless md
line = md[1]
return if line.nil?
case line
when /\A<[\w_:]/um
Element.parse_stream source, listener
when /\A<\//um
break
when CData::START_RE
CData.parse_stream source, listener
when Comment::START_RE
Comment.parse_stream source, listener
when Instruction::START_RE
Instruction.parse_stream source, listener
else
raise ParseException.new("malformed XML: bad content", source ) if md[1][0] == ?<
Text.parse_stream source, listener
end
end
#nregexp = Regexp.new("^\s*<\/#{name}\s*>", Regexp::MULTILINE, 'u')
#if source.match(nregexp, true)
if source.match(/^\s*<\/#{name}\s*>/, true)
listener.tag_end name
else
raise ParseException.new( "Missing end tag for #{name}",
source )
end
else
listener.tag_end name
end
rescue ParseException
$!.source = source
$!.element = self if self.kind_of? Element
raise
rescue Exception
raise
old_ex = $!
raise ParseException.new("unidentified error", source, self, old_ex)
end
end
|