File: document.rb

package info (click to toggle)
ruby-ox 2.1.1-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 540 kB
  • sloc: ansic: 7,178; ruby: 415; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 1,080 bytes parent folder | download | duplicates (3)
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

module Ox
  # Represents an XML document. It has a fixed set of attributes which form
  # the XML prolog. A Document includes Elements.
  class Document < Element
    # Create a new Document.
    # @param [Hash] prolog prolog attributes
    # @option prolog [String] :version version, typically '1.0' or '1.1'
    # @option prolog [String] :encoding encoding for the document, currently included but ignored
    # @option prolog [String] :standalone indicates the document is standalone
    def initialize(prolog={})
      super(nil)
      @attributes = { }
      @attributes[:version] = prolog[:version] unless prolog[:version].nil?
      @attributes[:encoding] = prolog[:encoding] unless prolog[:encoding].nil?
      @attributes[:standalone] = prolog[:standalone] unless prolog[:standalone].nil?
    end
    
    # Returns the first Element in the document.
    def root()
      unless !instance_variable_defined?(:@nodes) || @nodes.nil?
        @nodes.each do |n|
          return n if n.is_a?(::Ox::Element)
        end
      end
      nil
    end

  end # Document
end # Ox