As mentioned in issue #288, Mechanize's pluggable parser can be used to automatically parse requested XML documents. It is fairly common to encounter an XML document while using Mechanize. Therefore, Mechanize should include a parser for handling XML documents.
class XMLFile < Mechanize::File
def initialize uri = nil, response = nil, body = nil, code = nil
super uri, response, body, code
@doc = Nokogiri.parse body
agent = Mechanize.new
agent.pluggable_parser.xml = XMLFile
page = Mechanize.get 'http://example.com/foo.xml'
page #=> XMLFile
page.doc #=> Nokogiri::Document
This would not add any additional dependencies, as Mechanize already relies on Nokogiri.
Added Mechanize::XmlFile as default xml document parser
I've added this in a separate branch because I'm not really entirely sure about it, you could also argue that it would break compatibility with any applications using Mechanize to fetch XML files and expecting a Mechanize::File object (although XmlFile inherits from File so it shouldn't technically be an issue). It certainly needs more input, though.
Merged xml-file into master
updated changes for #289