# File rexml/document.rb, line 152 def Document.parse_stream( source, listener ) if source.kind_of? Source # do nothing elsif source.kind_of? IO source = IOSource.new(source) elsif source.kind_of? String source = Source.new source else raise "Unknown source type!" end while not source.empty? source.match( /^\s*/um, true ) word = source.match( /^\s*(<.*?)>/um ) word = word[1] unless word.nil? case word when nil word = source.match( /\s*(\S+)/um, true ) return if word.nil? raise "data found outside of root element ('#{nw}')" if nw.strip.length > 0 when Comment::START_RE Comment.parse_stream source, listener when DocType::START_RE DocType.parse_stream source, listener when XMLDecl::START_RE XMLDecl.parse_stream source, listener when Instruction::START_RE Instruction.parse_stream source, listener else Element.parse_stream source, listener end end # Here we need to check for invalid documents. end