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 18

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 89

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 73

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 70

alias :stand_alone? :standalone

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

[ GitHub ]

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

attr_accessor :version, :standalone

#version (rw)

[ GitHub ]

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

attr_accessor :version, :standalone

#writeencoding (readonly)

[ GitHub ]

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

attr_reader :writeencoding, :writethis

#writethis (readonly)

[ GitHub ]

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

attr_reader :writeencoding, :writethis

Instance Method Details

#==(other)

[ GitHub ]

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

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 36

def clone
  XMLDecl.new(self)
end

#content(enc) (private)

[ GitHub ]

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

def content(enc)
  rv = "version='#@version'"
  rv << " encoding='#{enc}'" if @writeencoding || enc !~ /\Autf-8\z/i
  rv << " standalone='#@standalone'" if @standalone
  rv
end

#dowrite

[ GitHub ]

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

def dowrite
  @writethis = true
end

#inspect

[ GitHub ]

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

def inspect
  START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
end

#node_type

[ GitHub ]

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

def node_type
  :xmldecl
end

#nowrite

[ GitHub ]

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

def nowrite
  @writethis = false
end

#old_enc=

[ GitHub ]

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

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 46

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

#xmldecl(version, encoding, standalone)

[ GitHub ]

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

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