File: xml.rb

package info (click to toggle)
ruby-roxml 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 800 kB
  • sloc: ruby: 4,133; xml: 1,013; makefile: 7
file content (40 lines) | stat: -rw-r--r-- 936 bytes parent folder | download | duplicates (5)
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
module ROXML
  PARSERS = %w[nokogiri libxml].freeze
  unless const_defined? 'XML_PARSER'
    parsers = PARSERS.dup
    begin
      require parsers.first
      XML_PARSER = parsers.first # :nodoc:
    rescue LoadError
      parsers.shift
      retry unless parsers.empty?
      raise "Could not load a parser. Tried #{PARSERS.to_sentence}"
    end
  end

  require File.join('roxml/xml/parsers', XML_PARSER)

  module XML
    class Node
      def self.from(data)
        case data
        when XML::Node
          data
        when XML::Document
          data.root
        when File, IO
          XML.parse_io(data).root
        else
          if (defined?(URI) && data.is_a?(URI::Generic)) ||
             (defined?(Pathname) && data.is_a?(Pathname))
            XML.parse_file(data.to_s).root
          else
            XML.parse_string(data).root
          end
        end
      end
    end
  end
end

require 'roxml/xml/references'