#pritty print xml require 'rexml/document' def pretty_print2(parent_node, itab) buffer = '' parent_node.elements.each do |node| buffer += ' ' * itab + "<#{node.name}#{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 + "\n" else node_text = node.text.strip if node_text != '' buffer += node_text buffer += "\n" else buffer += "\n" + pretty_print(node,itab+2) buffer += ' ' * itab + "\n" end end else buffer += "/>\n" end end buffer end def get_att_list2(node) att_list = '' node.attributes.each { |attribute, val| att_list += " #{attribute}='#{val}'" } att_list end def pretty_xml2(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_list2(doc.root)}" if doc.root.to_a.length > 0 buffer +=">\n#{pretty_print2(doc.root,2)}" else buffer += "/>\n" end return buffer end def loadxmlrecord2 if File.exist?(@a_viewdialogxml2.to_s.strip) xml_data = File.new(@a_viewdialogxml2.to_s.strip) doc = REXML::Document.new xml_data @xmlfileresult2 = pretty_xml2(doc) else @xmlfileresult2 =" #{@a_viewdialogxml2.to_s.strip} not found" end end