Sha256: 6b43539f56a221355f8954ae81218346ea4ce233150db15f729e953bd5056ab7

Contents?: true

Size: 1.99 KB

Versions: 3

Compression:

Stored size: 1.99 KB

Contents

  #pritty print xml
  require 'rexml/document'
 
     
       def pretty_print(parent_node, itab)
         buffer = ''
    
        parent_node.elements.each do |node|
    
         # buffer += '-' * itab + "<#{node.name}#{get_att_list(node)}"
      buffer += '-' * itab + "#{get_att_list(node)}"
          if node.to_a.length > 0
            buffer += ""
            if ! node.text.nil?
           #   buffer += "\n"
            #buffer += pretty_print(node,itab+2) 
            #buffer += '-' * itab + "--#{node.name}\n"
            #else
              node_text = node.text.strip
              if node_text != ''
                buffer += node_text 
                buffer += "--#{node.name}\n"        
              else
                buffer += "\n" + pretty_print(node,itab+2) 
		buffer  += "\n"
              #  buffer += '-' * itab + "--#{node.name}\n"        
              end
            end
          else
            buffer += "\n"
          end
          
        end
      buffer
      end
    
      def get_att_list(node)
        att_list = ''
        node.attributes.each { |attribute, val| 	
	if attribute == "TEXT"
	att_list += "#{val}" 
	end
	}
       
	att_list 
      end
      
      def pretty_xml(doc)
        buffer = ''
        xml_declaration = doc.to_s.match('<\?.*\?>').to_s
        buffer += "#{xml_declaration}\n" if not xml_declaration.nil?
       
        xml_doctype = doc.to_s.match('<\!.*\">').to_s
        buffer += "#{xml_doctype}\n" if not xml_doctype.nil?
        
        buffer += "<#{doc.root.name}#{get_att_list(doc.root)}"
	
        if doc.root.to_a.length > 0
          buffer +=">\n#{pretty_print(doc.root,2)}"
        else
        buffer += "\n"
end
return buffer
      end
    
def loadxmlrecord
	if File.exist?(@a_viewdialogxml.to_s.strip)
                xml_data = File.new(@a_viewdialogxml.to_s.strip)
              doc = REXML::Document.new xml_data
             @xmlfileresult = pretty_xml(doc)
        else
	    @xmlfileresult =" #{@a_viewdialogxml.to_s.strip} not found"
	end
  end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
rwddialogmap-0.02 code/superant.com.dialogmap/xmlprettyprint2.rb
rwddialogmap-0.01 code/superant.com.dialogmap/xmlprettyprint2.rb
rwdhypernote-0.16 code/superant.com.dialogmap/xmlprettyprint2.rb