123456789_123456789_123456789_123456789_123456789_

Class: REXML::XMLDecl

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Child
Instance Chain:
self, Encoding, Child, Node
Inherits: REXML::Child
Defined in: lib/rexml/xmldecl.rb

Overview

NEEDS DOCUMENTATION

Constant Summary

Class Method Summary

Child - Inherited

.new

Constructor.

Instance Attribute Summary

Encoding - Included

#encoding

ID —> Encoding name.

#encoding=

Child - Inherited

#next_sibling
#next_sibling=

Sets the next sibling of this child.

#parent

The Parent of this object.

#parent=

Sets the parent of this child to the supplied argument.

#previous_sibling
#previous_sibling=

Sets the previous sibling of this child.

Node - Included

Instance Method Summary

Encoding - Included

Child - Inherited

#bytes

This doesn’t yet handle encodings.

#document
Returns

the document this child belongs to, or nil if this child belongs to no document.

#remove

Removes this child from the parent.

#replace_with

Replaces this object with another object.

Node - Included

#each_recursive

Visit all subnodes of self recursively.

#find_first_recursive

Find (and return) first subnode (recursively) for which the block evaluates to true.

#indent,
#index_in_parent

Returns the position that self holds in its parent’s array, indexed from 1.

#next_sibling_node, #previous_sibling_node,
#to_s
indent

Constructor Details

.new(version = DEFAULT_VERSION, encoding = nil, standalone = nil) ⇒ XMLDecl

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 20

def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
  @writethis = true
  @writeencoding = !encoding.nil?
  if version.kind_of? XMLDecl
    super()
    @version = version.version
    self.encoding = version.encoding
    @writeencoding = version.writeencoding
    @standalone = version.standalone
  else
    super()
    @version = version
    self.encoding = encoding
    @standalone = standalone
  end
  @version = DEFAULT_VERSION if @version.nil?
end

Class Method Details

.default

Only use this if you do not want the XML declaration to be written; this object is ignored by the XML writer. Otherwise, instantiate your own XMLDecl and add it to the document.

Note that XML 1.1 documents must include an XML declaration

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 91

def XMLDecl.default
  rv = XMLDecl.new( "1.0" )
  rv.nowrite
  rv
end

Instance Attribute Details

#encoding=(enc) (writeonly)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 75

def encoding=( enc )
  if enc.nil?
    self.old_enc = "UTF-8"
    @writeencoding = false
  else
    self.old_enc = enc
    @writeencoding = true
  end
  self.dowrite
end

#stand_alone? (readonly)

Alias for #standalone.

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 72

alias :stand_alone? :standalone

#standalone (rw) Also known as: #stand_alone?

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 17

attr_accessor :version, :standalone

#version (rw)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 17

attr_accessor :version, :standalone

#writeencoding (readonly)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 18

attr_reader :writeencoding, :writethis

#writethis (readonly)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 18

attr_reader :writeencoding, :writethis

Instance Method Details

#==(other)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 55

def ==( other )
  other.kind_of?(XMLDecl) and
  other.version == @version and
  other.encoding == self.encoding and
  other.standalone == @standalone
end

#clone

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 38

def clone
  XMLDecl.new(self)
end

#content(enc) (private)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 110

def content(enc)
  context = nil
  context = parent.context if parent
  if context and context[:prologue_quote] == :quote
    quote = "\""
  else
    quote = "'"
  end

  rv = "version=#{quote}#{@version}#{quote}"
  if @writeencoding or enc !~ /\Autf-8\z/i
    rv << " encoding=#{quote}#{enc}#{quote}"
  end
  if @standalone
    rv << " standalone=#{quote}#{@standalone}#{quote}"
  end
  rv
end

#dowrite

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 101

def dowrite
  @writethis = true
end

#inspect

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 105

def inspect
  "#{START} ... #{STOP}"
end

#node_type

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 68

def node_type
  :xmldecl
end

#nowrite

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 97

def nowrite
  @writethis = false
end

#old_enc=

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 73

alias :old_enc= :encoding=

#write(writer, indent = -1,, transitive = false, ie_hack = false)

indent

Ignored. There must be no whitespace before an XML declaration

transitive

Ignored

ie_hack

Ignored

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 48

def write(writer, indent=-1, transitive=false, ie_hack=false)
  return nil unless @writethis or writer.kind_of? Output
  writer << START
  writer << " #{content encoding}"
  writer << STOP
end

#xmldecl(version, encoding, standalone)

[ GitHub ]

  
# File 'lib/rexml/xmldecl.rb', line 62

def xmldecl version, encoding, standalone
  @version = version
  self.encoding = encoding
  @standalone = standalone
end