File: xml_file.rb

package info (click to toggle)
ruby-mechanize 2.7.6-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,480 kB
  • sloc: ruby: 11,380; makefile: 5; sh: 4
file content (47 lines) | stat: -rw-r--r-- 1,275 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
##
# 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')

class Mechanize::XmlFile < Mechanize::File
  extend Forwardable

  # The underlying Nokogiri::XML::Document object

  attr_reader :xml

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

  ##
  # :method: search
  #
  # Search for +paths+ in the page using Nokogiri's #search.  The +paths+ can
  # be XPath or CSS and an optional Hash of namespaces may be appended.
  #
  # See Nokogiri::XML::Node#search for further details.

  def_delegator :xml, :search, :search

  ##
  # :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

  def_delegator :xml, :at, :at
end