From: "mythpills P." Date: 2011-12-08T16:54:50+09:00 Subject: remove newline characters in d anchors hi i am working on this code where i need to list the files in a dir and store it in a xml, which i managed to do. however in the generated xml there are newline characters (\n) appearing before and after the actual text value of each node. below is the code i am using require 'rexml/document' require 'find' doc = REXML::Document.new main = doc.add_element 'main' main.attributes['name'] = "" # Find.find('./'){|path| puts path[2,path.length] } Find.find('./'){|path| if path != './dirlisting.rb' if ! File::directory? ( path ) newfile = main.add_element 'file' newfile.text = path[2,path.length] end end } outfile = open('dirlist.xml', 'w') doc.write(outfile, 0) # open('dirlist.xml', 'w') { |f| f << doc} below is the sample output in the xml wid newline characters before & after each text value within the anchors
340330_10150281813536470_96585976469_8235727_1982670115_o.jpg 507999446_JUN2009.pdf 8.10669690.00.00.100193.pdf Asset List_Tracker.xls BM.jpg BM2.JPG
how can i get rid of those line breaks in each nodes and have a clean node with just the text value? Attachments: http://www.ruby-forum.com/attachment/6825/dirlisting.rb -- Posted via http://www.ruby-forum.com/.