Sha256: eb88f06fb8383f56555a8e7597f68d09c6bee7a7fd6613d2784b49045c57139f

Contents?: true

Size: 1.61 KB

Versions: 6

Compression:

Stored size: 1.61 KB

Contents

module Nokogiri
  module XML
    ####
    # Nokogiri::XML::Document is the main entry point for dealing with
    # XML documents.  The Document is created by parsing an XML document.
    # See Nokogiri.XML()
    #
    # For searching a Document, see Nokogiri::XML::Node#css and
    # Nokogiri::XML::Node#xpath
    class Document < Node
      # A list of Nokogiri::XML::SyntaxError found when parsing a document
      attr_accessor :errors

      # The name of this document.  Always returns "document"
      def name
        'document'
      end

      # A reference to +self+
      def document
        self
      end

      # Get the list of decorators given +key+
      def decorators(key)
        @decorators ||= Hash.new
        @decorators[key] ||= []
      end

      ###
      # Explore a document with shortcut methods.
      def slop!
        unless decorators(XML::Node).include? Nokogiri::Decorators::Slop
          decorators(XML::Node) << Nokogiri::Decorators::Slop
          decorate!
        end

        self
      end

      ###
      # Apply any decorators to +node+
      def decorate(node)
        return unless @decorators
        @decorators.each { |klass,list|
          next unless node.is_a?(klass)
          list.each { |moodule| node.extend(moodule) }
        }
      end

      def node_cache # :nodoc:
        @node_cache ||= {}
      end

      alias :to_xml :serialize
      alias :inner_html :serialize

      # Get the hash of namespaces on the root Nokogiri::XML::Node
      def namespaces
        root ? root.collect_namespaces : {}
      end

      undef_method :swap, :parent, :namespace
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nokogiri-1.2.2-java lib/nokogiri/xml/document.rb
nokogiri-1.2.2-x86-mswin32-60 lib/nokogiri/xml/document.rb
nokogiri-1.2.2 lib/nokogiri/xml/document.rb
nokogiri-1.2.3-java lib/nokogiri/xml/document.rb
nokogiri-1.2.3 lib/nokogiri/xml/document.rb
nokogiri-1.2.3-x86-mswin32-60 lib/nokogiri/xml/document.rb