require 'htree/encoder' require 'htree/doc' require 'htree/elem' require 'htree/leaf' require 'htree/text' module HTree # :stopdoc: class Text ChRef = { '>' => '>', '<' => '<', '"' => '"', } def output(out, context=nil) out.output_text @rcdata.gsub(/[<>]/) {|s| ChRef[s] } end def to_attvalue_content @rcdata.gsub(/[<>"]/) {|s| ChRef[s] } end def output_attvalue(out, context) out.output_string '"' out.output_text to_attvalue_content out.output_string '"' end def output_cdata(out) str = self.to_s if %r{" children_context end def output_stag(out, context) out.output_string '<' @name.output(out, context) children_context = output_attributes(out, context) out.output_string "\n>" children_context end def output_etag(out, context) out.output_string '" end end class Context def output_namespaces(out, outer_context) unknown_namespaces = {} @namespaces.each {|prefix, uri| outer_uri = outer_context.namespace_uri(prefix) if outer_uri == nil unknown_namespaces[prefix] = uri elsif outer_uri != uri if prefix out.output_string " xmlns:#{prefix}=" else out.output_string " xmlns=" end Text.new(uri).output_attvalue(out, outer_context) end } unless unknown_namespaces.empty? out.output_xmlns(unknown_namespaces) end outer_context.subst_namespaces(@namespaces) end end class BogusETag # don't output anything. def output(out, context) end end class XMLDecl # don't output anything. def output(out, context) end def output_prolog_xmldecl(out, context) out.output_string "" end end class DocType def output(out, context) out.output_string "" end def generate_content # :nodoc: result = '' if @public_identifier result << "PUBLIC \"#{@public_identifier}\"" else result << "SYSTEM" end # Although a system identifier is not omissible in XML, # we cannot output it if it is not given. if @system_identifier if /"/ !~ @system_identifier result << " \"#{@system_identifier}\"" else result << " '#{@system_identifier}'" end end result end end class ProcIns def output(out, context) out.output_string "" end end class Comment def output(out, context) out.output_string "" end end # :startdoc: end