Class: Mechanize::XmlFile

Inherits:
File
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mechanize/xml_file.rb

Overview

This class encapsulates an XML file. If Mechanize finds a content-type of ‘text/xml’ or ‘application/xml’ this class will be instantiated and returned. This class also opens up the search and at methods available on the underlying Nokogiri::XML::Document object.

Example:

require 'mechanize'

agent = Mechanize.new
xml = agent.get('http://example.org/some-xml-file.xml')
xml.class #=> Mechanize::XmlFile
xml.search('//foo[@attr="bar"]/etc')

Constant Summary

Constants included from Parser

Parser::SPECIAL_FILENAMES

Instance Attribute Summary collapse

Attributes inherited from File

#body, #filename

Attributes included from Parser

#code, #response, #uri

Instance Method Summary collapse

Methods inherited from File

#save, #save!

Methods included from Parser

#extract_filename, #fill_header, #find_free_name

Constructor Details

#initialize(uri = nil, response = nil, body = nil, code = nil) ⇒ XmlFile

Returns a new instance of XmlFile.



24
25
26
27
# File 'lib/mechanize/xml_file.rb', line 24

def initialize(uri = nil, response = nil, body = nil, code = nil)
  super uri, response, body, code
  @xml = Nokogiri.XML body
end

Instance Attribute Details

#xmlObject (readonly)

:method: at

Search through the page for path under namespace using Nokogiri’s #at. The path may be either a CSS or XPath expression.

See also Nokogiri::XML::Node#at



22
23
24
# File 'lib/mechanize/xml_file.rb', line 22

def xml
  @xml
end