1 require 'booh/rexml/encoding'
2 require 'booh/rexml/source'
9 DEFAULT_VERSION = "1.0";
10 DEFAULT_ENCODING = "UTF-8";
11 DEFAULT_STANDALONE = "no";
15 attr_accessor :version, :standalone
16 attr_reader :writeencoding
18 def initialize(version=DEFAULT_VERSION, encoding=nil, standalone=nil)
20 @writeencoding = !encoding.nil?
21 if version.kind_of? XMLDecl
23 @version = version.version
24 self.encoding = version.encoding
25 @writeencoding = version.writeencoding
26 @standalone = version.standalone
30 self.encoding = encoding
31 @standalone = standalone
33 @version = DEFAULT_VERSION if @version.nil?
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}"
47 writer << " #{content encoding}"
49 writer << STOP.sub(/\\/u, '')
53 other.kind_of?(XMLDecl) and
54 other.version == @version and
55 other.encoding == self.encoding and
56 other.standalone == @standalone
59 def xmldecl version, encoding, standalone
61 self.encoding = encoding
62 @standalone = standalone
69 alias :stand_alone? :standalone
70 alias :old_enc= :encoding=
74 self.old_enc = "UTF-8"
75 @writeencoding = false
83 # Only use this if you do not want the XML declaration to be written;
84 # this object is ignored by the XML writer. Otherwise, instantiate your
85 # own XMLDecl and add it to the document.
87 # Note that XML 1.1 documents *must* include an XML declaration
89 rv = XMLDecl.new( "1.0" )
103 START.sub(/\\/u, '') + " ... " + STOP.sub(/\\/u, '')
108 rv = "version='#@version'"
109 rv << " encoding='#{enc}'" if @writeencoding || enc !~ /utf-8/i
110 rv << " standalone='#@standalone'" if @standalone