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] | |
writethis | [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 93 93: def XMLDecl.default 94: rv = XMLDecl.new( "1.0" ) 95: rv.nowrite 96: rv 97: 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 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
# 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
# File lib/rexml/xmldecl.rb, line 107 107: def inspect 108: START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '') 109: end
indent: | Ignored. There must be no whitespace before an XML declaration |
transitive: | Ignored |
ie_hack: | Ignored |
# 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
# 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