Topic: Parse http login/password protected XML file ?

I have to read xml files that are accessibles through http with authentication.  That's why I use mechanize (I was able to successfully read it with nokogiri on an unprotected site)

My problem is that I can't get mechanize to recognize these XML files so I can use .find or .search on them.

Here is what I tried first - in my view (html file) (Example with an unprotected file but the real one will be http login/pass protected)

<% agent = Mechanize.new %>
<% page = agent.get("http://dl.dropbox.com/u/344349/xml.xml") %>
<%= page %>

Which returns #<Mechanize::File:0x007f9dd602de30>. It's ::File and not ::Page
I can't use a .find or .search on this as it'll error with undefined method find for #<Mechanize::File:0x007f9dd624cbd0>

Mechanize doc says : This is the default (and base) class for the Pluggable Parsers. If Mechanize cannot find an appropriate class to use for the content type, this class will be used. For example, if you download a JPG, Mechanize will not know how to parse it, so this class will be instantiated.

So I created a class as described here : http://rdoc.info/github/tenderlove/mech … ableParser

My class
class XMLParser < Mechanize::File+
attr_reader :xml
def initialize(uri=nil, response=nil, body=nil, code=nil)
super(uri, response, body, code)`
@xml = xml.parse(body)
end
end

and the updated code in my view (html file)


<% agent = Mechanize.new %>
<% agent.pluggable_parser['text/xml'] = XMLParser %>
<% agent.user_agent_alias = 'Windows Mozilla' %>
<% page = agent.get("http://dl.dropbox.com/u/344349/xml.xml") %>
<%= page %>

or even

<% agent = Mechanize.new  %>
<% agent.pluggable_parser.xml = XMLParser %>
<% page1 = agent.get('http://dl.dropbox.com/u/344349/xml.xml')  # => CSVParser %>
<%= page1 %>

Still returns #<Mechanize::File:0x007f9dd5253b48>

I even tested the exact code (CSVParser - http://rdoc.info/github/tenderlove/mech … bleParser) and tried loading a csv file that is still seen as a ::File.

What am I doing wrong ?  Any other gem (or built in) suggestions ?