class Ox::Document

Represents an XML document. It has a fixed set of attributes which form the XML prolog. A Document includes Elements.

Public Class Methods

new(prolog={}) click to toggle source

Create a new Document.

  • prolog [Hash] prolog attributes

    • :version [String] version, typically '1.0' or '1.1'

    • :encoding [String] encoding for the document, currently included but ignored

    • :standalone [String] indicates the document is standalone

Calls superclass method
# File lib/ox/document.rb, line 11
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

Public Instance Methods

root() click to toggle source

Returns the first Element in the document.

# File lib/ox/document.rb, line 20
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