| Class | REXML::XMLDecl |
| In: |
lib/rexml/xmldecl.rb
|
| Parent: | Child |
NEEDS DOCUMENTATION
| DEFAULT_VERSION | = | "1.0"; |
| DEFAULT_ENCODING | = | "UTF-8"; |
| DEFAULT_STANDALONE | = | "no"; |
| START | = | '<\?xml'; |
| STOP | = | '\?>'; |
| standalone | -> | stand_alone? |
| encoding= | -> | old_enc= |
| standalone | [RW] | |
| version | [RW] | |
| writeencoding | [R] |
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
# File lib/rexml/xmldecl.rb, line 88
88: def XMLDecl.default
89: rv = XMLDecl.new( "1.0" )
90: rv.nowrite
91: rv
92: end
# 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
# 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
# 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
# File lib/rexml/xmldecl.rb, line 102
102: def inspect
103: START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
104: end
# 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
# 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