Class REXML::XMLDecl
In: lib/rexml/xmldecl.rb
Parent: Child

NEEDS DOCUMENTATION

Methods

==   clone   content   default   dowrite   encoding=   inspect   new   node_type   nowrite   write   xmldecl  

Included Modules

Encoding

Constants

DEFAULT_VERSION = "1.0";
DEFAULT_ENCODING = "UTF-8";
DEFAULT_STANDALONE = "no";
START = '<\?xml';
STOP = '\?>';

External Aliases

standalone -> stand_alone?
encoding= -> old_enc=

Attributes

standalone  [RW] 
version  [RW] 
writeencoding  [R] 
writethis  [R] 

Public Class methods

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

[Source]

    # File lib/rexml/xmldecl.rb, line 93
93:     def XMLDecl.default
94:       rv = XMLDecl.new( "1.0" )
95:       rv.nowrite
96:       rv
97:     end

[Source]

    # File lib/rexml/xmldecl.rb, line 18
18:                 def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
19:       @writethis = true
20:       @writeencoding = !encoding.nil?
21:                         if version.kind_of? XMLDecl
22:                                 super()
23:                                 @version = version.version
24:                                 self.encoding = version.encoding
25:         @writeencoding = version.writeencoding
26:                                 @standalone = version.standalone
27:                         else
28:                                 super()
29:                                 @version = version
30:                                 self.encoding = encoding
31:                                 @standalone = standalone
32:                         end
33:                         @version = DEFAULT_VERSION if @version.nil?
34:                 end

Public Instance methods

[Source]

    # File lib/rexml/xmldecl.rb, line 57
57:                 def ==( other )
58:                   other.kind_of?(XMLDecl) and
59:                   other.version == @version and
60:                   other.encoding == self.encoding and
61:                   other.standalone == @standalone
62:                 end

[Source]

    # File lib/rexml/xmldecl.rb, line 36
36:                 def clone
37:                         XMLDecl.new(self)
38:                 end

[Source]

     # File lib/rexml/xmldecl.rb, line 103
103:     def dowrite
104:       @writethis = true
105:     end

[Source]

    # File lib/rexml/xmldecl.rb, line 77
77:     def encoding=( enc )
78:       if enc.nil?
79:         self.old_enc = "UTF-8"
80:         @writeencoding = false
81:       else
82:         self.old_enc = enc
83:         @writeencoding = true
84:       end
85:       self.dowrite
86:     end

[Source]

     # File lib/rexml/xmldecl.rb, line 107
107:     def inspect
108:       START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
109:     end

[Source]

    # File lib/rexml/xmldecl.rb, line 70
70:                 def node_type
71:                         :xmldecl
72:                 end

[Source]

     # File lib/rexml/xmldecl.rb, line 99
 99:     def nowrite
100:       @writethis = false
101:     end
indent:Ignored. There must be no whitespace before an XML declaration
transitive:Ignored
ie_hack:Ignored

[Source]

    # File lib/rexml/xmldecl.rb, line 46
46:                 def write(writer, indent=-1, transitive=false, ie_hack=false)
47:       return nil unless @writethis or writer.kind_of? Output
48:                         writer << START.sub(/\\/u, '')
49:       if writer.kind_of? Output
50:         writer << " #{content writer.encoding}"
51:       else
52:         writer << " #{content encoding}"
53:       end
54:                         writer << STOP.sub(/\\/u, '')
55:                 end

[Source]

    # File lib/rexml/xmldecl.rb, line 64
64:                 def xmldecl version, encoding, standalone
65:                         @version = version
66:                         self.encoding = encoding
67:                         @standalone = standalone
68:                 end

Private Instance methods

[Source]

     # File lib/rexml/xmldecl.rb, line 112
112:                 def content(enc)
113:                         rv = "version='#@version'"
114:                         rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i
115:                         rv << " standalone='#@standalone'" if @standalone
116:                         rv
117:                 end

[Validate]