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] 

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 88
88:     def XMLDecl.default
89:       rv = XMLDecl.new( "1.0" )
90:       rv.nowrite
91:       rv
92:     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 52
52:                 def ==( other )
53:                   other.kind_of?(XMLDecl) and
54:                   other.version == @version and
55:                   other.encoding == self.encoding and
56:                   other.standalone == @standalone
57:                 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 98
 98:     def dowrite
 99:       @writethis = true
100:     end

[Source]

    # File lib/rexml/xmldecl.rb, line 72
72:     def encoding=( enc )
73:       if enc.nil?
74:         self.old_enc = "UTF-8"
75:         @writeencoding = false
76:       else
77:         self.old_enc = enc
78:         @writeencoding = true
79:       end
80:       self.dowrite
81:     end

[Source]

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

[Source]

    # File lib/rexml/xmldecl.rb, line 65
65:                 def node_type
66:                         :xmldecl
67:                 end

[Source]

    # File lib/rexml/xmldecl.rb, line 94
94:     def nowrite
95:       @writethis = false
96:     end

[Source]

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

[Source]

    # File lib/rexml/xmldecl.rb, line 59
59:                 def xmldecl version, encoding, standalone
60:                         @version = version
61:                         self.encoding = encoding
62:                         @standalone = standalone
63:                 end

Private Instance methods

[Source]

     # File lib/rexml/xmldecl.rb, line 107
107:                 def content(enc)
108:                         rv = "version='#@version'"
109:                         rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i
110:                         rv << " standalone='#@standalone'" if @standalone
111:                         rv
112:                 end

[Validate]