I am having trouble getting xmlSimple to run correctly in my .rb file. I am using xmlSimple.xmlIn(filename);
, however, it seems there is an error with finding the correct file. I have moved the file to the bin and the file exists, meaning, filename.exists? = true
. Any ideas on the possible error source? Thanks!
-Edit- Let me add this information; I am very new to Ruby and there is a good chance my method or syntax is completely wrong, here is my code in the .rb file:
require 'xmlsimple'
file_name = 'xmldatatest.xml'
paragraph_str = 0
file = File.open(file_name) # takes XML Data and creates a file of the data
File.open(file_name, "w+") do |f| # open file for update
lines = f.readlines # read into array of lines
lines.each do
|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 do
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 the program is to strip all escape characters from the original XML file and then replace each "Paragraph#" node within a <p>
and </p>
tag. After which, the file would be parsed using XmlSimple.Xml_in(filename)
. Any suggestions or corrections are more than appreciated.