xml - Using xmlSimple.xmlIn(file) With Ruby -


i having trouble getting xmlsimple run correctly in .rb file. using xmlsimple.xmlin(filename);, however, seems there error finding correct file. have moved file bin , file exists, meaning, filename.exists? = true. ideas on possible error source? thanks!

-edit- let me add information; new ruby , there chance method or syntax wrong, here code in .rb file:

require 'xmlsimple'  file_name = 'xmldatatest.xml'  paragraph_str = 0  file = file.open(file_name) # takes xml data , creates file of data  file.open(file_name, "w+") |f|     # open file update  lines = f.readlines           # read array of lines  lines.each       |it|                              # modify lines         it.gsub!(/\n/, '')     it.gsub!('<p>', '')     it.gsub!('</p>', '')     it.gsub!('\"paragraph.\"', 'paragraph')     if ((it.include? ('paragraph')) == 1)     paragraph_str += 1     end     while paragraph_str > 0      initial_value = paragraph_str      if ((paragraph_str == initial_value))     it.gsub!(/paragraph/, '<p>')     paragraph_str -= 1     else      it.gsub!(/paragraph/, '</p><p>')     paragraph_str -= 1     end      end         f.print lines                 # write out modified lines     end end  file.open(file_name, 'a') {|f| f.puts "</p>" }  ref  = xmlsimple.xml_in(file_name) 

the purpose of program strip escape characters original xml file , replace each "paragraph#" node within <p> , </p> tag. after which, file parsed using xmlsimple.xml_in(filename). suggestions or corrections more appreciated.

it understanding that, in ruby, xml dead slow unless bound c library. , nokogiri best maintained of lot.

adding this, re question:

however, seems there error finding correct file

if you're using threads , checking if file exists, may return true|false in if statement opposite might true time it's read.

adding further usual yada yada parsing html using regex applies/


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -