Sha256: ce156056c6e3a1c1ca8d29c56473bb853c1c2ef0cd245c045b92a27b009d6c2f

Contents?: true

Size: 1.06 KB

Versions: 30

Compression:

Stored size: 1.06 KB

Contents

module Nokogiri
  module XML
    class Node

      ###
      # Serialize Node using +options+.  Save options can also be set using a
      # block. See SaveOptions.
      #
      # These two statements are equivalent:
      #
      #  node.serialize(:encoding => 'UTF-8', :save_with => FORMAT | AS_XML)
      #
      # or
      #
      #   node.serialize(:encoding => 'UTF-8') do |config|
      #     config.format.as_xml
      #   end
      #
      def serialize *args, &block
        options = args.first.is_a?(Hash) ? args.shift : {
          :encoding   => args[0],
          :save_with  => args[1] || SaveOptions::FORMAT
        }

        encoding = options[:encoding] || document.encoding

        outstring = ""
        if encoding && outstring.respond_to?(:force_encoding)
          begin
            outstring.force_encoding(Encoding.find(encoding))
          rescue
            outstring.force_encoding(Encoding.find('UTF-8'))
          end
        end
        io = StringIO.new(outstring)
        write_to io, options, &block
        io.string
      end

    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
arachni-0.4.1 lib/arachni/nokogiri/xml/node.rb
arachni-0.4.0.4 lib/arachni/nokogiri/xml/node.rb
arachni-0.4.0.3 lib/arachni/nokogiri/xml/node.rb
arachni-0.4.0.2 lib/arachni/nokogiri/xml/node.rb
arachni-0.4.0.1 lib/arachni/nokogiri/xml/node.rb
arachni-0.4 lib/arachni/nokogiri/xml/node.rb
arachni-0.3 lib/nokogiri/xml/node.rb
arachni-0.2.4 lib/nokogiri/xml/node.rb
arachni-0.2.3 lib/nokogiri/xml/node.rb
arachni-0.2.2.2 lib/nokogiri/xml/node.rb