Class WWW::Mechanize::REXMLPage
In: lib/mechanize/parsers/rexml_page.rb
Parent: WWW::Mechanize::Page
Mechanize\n[lib/mechanize.rb\nlib/mechanize/cookie.rb\nlib/mechanize/errors.rb\nlib/mechanize/form.rb\nlib/mechanize/form_elements.rb\nlib/mechanize/history.rb\nlib/mechanize/list.rb\nlib/mechanize/page.rb\nlib/mechanize/page_elements.rb\nlib/mechanize/pluggable_parsers.rb] lib/mechanize.rb WWW dot/m_19_0.png

Methods

new  

Public Class methods

[Source]

    # File lib/mechanize/parsers/rexml_page.rb, line 5
 5:   def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
 6:     @body           = body
 7:     @watch_for_set  = {}
 8:     @mech           = mech
 9: 
10:     # construct parser and feed with HTML
11:     parser = HTMLTree::XMLParser.new
12:     begin
13:       parser.feed(@body)
14:     rescue => ex
15:       if ex.message =~ /attempted adding second root element to document/ and
16:         # Put the whole document inside a single root element, which I
17:         # simply name <root>, just to make the parser happy. It's no
18:         #longer valid HTML, but without a single root element, it's not
19:         # valid HTML as well.
20: 
21:         # TODO: leave a possible doctype definition outside this element.
22:         parser = HTMLTree::XMLParser.new
23:         parser.feed("<root>" + @body + "</root>")
24:       else
25:         raise
26:       end
27:     end
28: 
29:     @root = parser.document
30: 
31:     yield self if block_given?
32: 
33:     super(uri, response, body, code)
34:   end

[Validate]