In Files
- rexml/formatters/default.rb
 
Parent
Class/Module Index
          ![show/hide quicksearch [+]](../../images/find.png)
        
        - Array
 - Fixnum
 - Float
 - Object
 - REXML
 - REXML::AttlistDecl
 - REXML::Attribute
 - REXML::Attributes
 - REXML::CData
 - REXML::Child
 - REXML::Comment
 - REXML::DTD
 - REXML::DTD::AttlistDecl
 - REXML::DTD::ElementDecl
 - REXML::DTD::EntityDecl
 - REXML::DTD::NotationDecl
 - REXML::DTD::Parser
 - REXML::Declaration
 - REXML::DocType
 - REXML::Document
 - REXML::Element
 - REXML::ElementDecl
 - REXML::Elements
 - REXML::Encoding
 - REXML::Entity
 - REXML::EntityConst
 - REXML::ExternalEntity
 - REXML::Formatters
 - REXML::Formatters::Default
 - REXML::Formatters::Pretty
 - REXML::Formatters::Transitive
 - REXML::Functions
 - REXML::IOSource
 - REXML::Instruction
 - REXML::Light
 - REXML::Light::Node
 - REXML::Namespace
 - REXML::Node
 - REXML::NotationDecl
 - REXML::Output
 - REXML::Parent
 - REXML::ParseException
 - REXML::Parsers
 - REXML::Parsers::BaseParser
 - REXML::Parsers::LightParser
 - REXML::Parsers::PullEvent
 - REXML::Parsers::PullParser
 - REXML::Parsers::SAX2Parser
 - REXML::Parsers::StreamParser
 - REXML::Parsers::TreeParser
 - REXML::Parsers::UltraLightParser
 - REXML::Parsers::XPathParser
 - REXML::QuickPath
 - REXML::SAX2Listener
 - REXML::Security
 - REXML::Source
 - REXML::SourceFactory
 - REXML::StreamListener
 - REXML::SyncEnumerator
 - REXML::Text
 - REXML::UndefinedNamespaceException
 - REXML::Validation
 - REXML::Validation::Choice
 - REXML::Validation::Event
 - REXML::Validation::Interleave
 - REXML::Validation::OneOrMore
 - REXML::Validation::Optional
 - REXML::Validation::Ref
 - REXML::Validation::RelaxNG
 - REXML::Validation::Sequence
 - REXML::Validation::State
 - REXML::Validation::ValidationException
 - REXML::Validation::Validator
 - REXML::Validation::ZeroOrMore
 - REXML::XMLDecl
 - REXML::XMLTokens
 - REXML::XPath
 - REXML::XPathParser
 - Symbol
 
REXML::Formatters::Default
Public Class Methods
            new( ie_hack=false )
            
          
          
          Prints out the XML document with no formatting – except if id_hack is set.
- ie_hack
 - 
If set to true, then inserts whitespace before the close of an empty tag, so that IE’s bad XML parser doesn’t choke.
 
 
               # File rexml/formatters/default.rb, line 11
def initialize( ie_hack=false )
  @ie_hack = ie_hack
end
             
            Public Instance Methods
            write( node, output )
            
          
          
          Writes the node to some output.
- node
 - 
The node to write
 - output
 - 
A class implementing
<<. Pass in an Output object to change the output encoding. 
 
               # File rexml/formatters/default.rb, line 22
def write( node, output )
  case node
  when Document
    if node.xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output)
      output = Output.new( output, node.xml_decl.encoding )
    end
    write_document( node, output )
  when Element
    write_element( node, output )
  when Declaration, ElementDecl, NotationDecl, ExternalEntity, Entity,
       Attribute, AttlistDecl
    node.write( output,-1 )
  when Instruction
    write_instruction( node, output )
  when DocType, XMLDecl
    node.write( output )
  when Comment
    write_comment( node, output )
  when CData
    write_cdata( node, output )
  when Text
    write_text( node, output )
  else
    raise Exception.new("XML FORMATTING ERROR")
  end
end
             
            Protected Instance Methods
            write_cdata( node, output )
            
          
          
           
               # File rexml/formatters/default.rb, line 97
def write_cdata( node, output )
  output << CData::START
  output << node.to_s
  output << CData::STOP
end
             
            
            write_comment( node, output )
            
          
          
           
               # File rexml/formatters/default.rb, line 91
def write_comment( node, output )
  output << Comment::START
  output << node.to_s
  output << Comment::STOP
end
             
            
            write_document( node, output )
            
          
          
           
               # File rexml/formatters/default.rb, line 60
def write_document( node, output )
  node.children.each { |child| write( child, output ) }
end
             
            
            write_element( node, output )
            
          
          
           
               # File rexml/formatters/default.rb, line 64
def write_element( node, output )
  output << "<#{node.expanded_name}"
  node.attributes.to_a.map { |a|
    Hash === a ? a.values : a
  }.flatten.sort_by {|attr| attr.name}.each do |attr|
    output << " "
    attr.write( output )
  end unless node.attributes.empty?
  if node.children.empty?
    output << " " if @ie_hack
    output << "/"
  else
    output << ">"
    node.children.each { |child|
      write( child, output )
    }
    output << "</#{node.expanded_name}"
  end
  output << ">"
end