Help please with REXML

hello,

I am trying to make a simple ruby script that can look at a set of xml
files, and make a set of folders based on the content of the XML files.
As it stands I can import the data with REXML, but when I run the script
I get a set of errors(I posted below the code) talking about TypeError.

Take a look below and let me know what you think…
CODE_
#!/usr/bin/ruby

require ‘rexml/document’
include REXML

jnumber_file = File.new(“XML_EXPORT/export_j_number.xml”)
jname_file = File.new(“XML_EXPORT/export_j_name.xml”)
cnumber_file = File.new(“XML_EXPORT/export_cnumber.xml”)
cname_file = File.new(“XML_EXPORT/export_c_name.xml”)

jnumber_file = Document.new(jnumber_file)
jname_file = Document.new(jname_file)
cnumber_file = Document.new(cnumber_file)
cname_file = Document.new(cname_file)

puts jnumber_file
puts jname_file
puts cnumbe_file
puts cname_file

class Job
attr_accessor :client_num, :client_name, :job_num, :job_name;

def generate_files()
# print “Client Num is " + @client_num.to_s + “\n”
client_dir = @client_num.to_s + “" + @client_name
job_dir = @job_num.to_s + "
” + @job_name
if(! File.exist?(client_dir))
Dir.mkdir(client_dir);
end
Dir.mkdir(client_dir+”/"+job_dir);

Dir.mkdir(client_dir+"/"+job_dir+"/parent");
Dir.mkdir(client_dir+"/"+job_dir+"/parent/old");
Dir.mkdir(client_dir+"/"+job_dir+"/parent/current");

Dir.mkdir(client_dir+"/"+job_dir+"/children");
Dir.mkdir(client_dir+"/"+job_dir+"/children/old");
Dir.mkdir(client_dir+"/"+job_dir+"/children/current");

end
end

j = Job.new
j.client_name = cname
j.client_num = cnumberfile
j.job_name = cname
j.job_num = jname_file
j.generate_files()
___END CODE
ERROE

director_v3.rb:28:in +': can't convert REXML::Document into String (TypeError) from director_v4.rb:28:ingenerate_files’
from director_v4.rb:50
____END ERROR

Anything yall can see to help would be awsome!

Thanks

If you can afford the time to install Nokogiri, this might be a good
direction to take.
It has better mindshare at the moment.
Anyways, could you re-run with the formatting below?
(One typo found).

MarkT

#=================================
require ‘rexml/document’
include REXML
class Job
attr_accessor :client_num, :client_name, :job_num, :job_name

def generate_files()
client_dir = @client_num.to_s + “" + @client_name
job_dir = @job_num.to_s + "
” + @job_name
unless File.exist?(client_dir) then Dir.mkdir(client_dir) end
Dir.mkdir(client_dir+"/"+job_dir)
Dir.mkdir(client_dir+"/"+job_dir+"/parent")
Dir.mkdir(client_dir+"/"+job_dir+"/parent/old")
Dir.mkdir(client_dir+"/"+job_dir+"/parent/current")
Dir.mkdir(client_dir+"/"+job_dir+"/children")
Dir.mkdir(client_dir+"/"+job_dir+"/children/old")
Dir.mkdir(client_dir+"/"+job_dir+"/children/current") end end

def declareFiles
jnumber_file = File.new(“XML_EXPORT/export_j_number.xml”)
jname_file = File.new(“XML_EXPORT/export_j_name.xml”)
cnumber_file = File.new(“XML_EXPORT/export_cnumber.xml”)
cname_file = File.new(“XML_EXPORT/export_c_name.xml”)
jnumber_file = Document.new(jnumber_file)
jname_file = Document.new(jname_file)
cnumber_file = Document.new(cnumber_file)
cname_file = Document.new(cname_file) end

j = Job.new
j.client_name = cname
j.client_num = cnumberfile
j.job_name = cname
j.job_num = jname_file
j.declareFiles
puts jnumber_file, jname_file, cnumber_file, cname_file
j.generate_files()
#=================================

Thank you for you help!
Sadly this didn’t end up working I got errors (posted below)

ERROR________
undefined local variable or method `cnumber_file’ for main:Object
(NameError)
END ERROR____

again sorry for the newness and thanks!!! fro your help

#=================================
require ‘rexml/document’
include REXML
class Job
attr_accessor :client_num, :client_name, :job_num, :job_name

def generate_files()
client_dir = @client_num.to_s + “" + @client_name
job_dir = @job_num.to_s + "
” + @job_name
unless File.exist?(client_dir) then Dir.mkdir(client_dir) end
Dir.mkdir(client_dir+"/"+job_dir)
Dir.mkdir(client_dir+"/"+job_dir+"/parent")
Dir.mkdir(client_dir+"/"+job_dir+"/parent/old")
Dir.mkdir(client_dir+"/"+job_dir+"/parent/current")
Dir.mkdir(client_dir+"/"+job_dir+"/children")
Dir.mkdir(client_dir+"/"+job_dir+"/children/old")
Dir.mkdir(client_dir+"/"+job_dir+"/children/current") end end

def declareFiles
jnumber_file = File.new(“XML_EXPORT/export_j_number.xml”)
jname_file = File.new(“XML_EXPORT/export_j_name.xml”)
cnumber_file = File.new(“XML_EXPORT/export_cnumber.xml”)
cname_file = File.new(“XML_EXPORT/export_c_name.xml”)
jnumber_file = Document.new(jnumber_file)
jname_file = Document.new(jname_file)
cnumber_file = Document.new(cnumber_file)
cname_file = Document.new(cname_file) end

j = Job.new
j.client_name = cname
j.client_num = cnumberfile
j.job_name = cname
j.job_num = jname_file
j.declareFiles
puts jnumber_file, jname_file, cnumber_file, cname_file
j.generate_files()
#=================================

On Fri, Jul 16, 2010 at 1:23 AM, Ben M. [email protected] wrote:

hello,

I am trying to make a simple ruby script that can look at a set of xml
files, and make a set of folders based on the content of the XML files.
As it stands I can import the data with REXML, but when I run the script
I get a set of errors(I posted below the code) talking about TypeError.

Take a look below and let me know what you think…

$ ruby /tmp/code_below
/tmp/code_below:6:in initialize': No such file or directory - XML_EXPORT/export_j_number.xml (Errno::ENOENT) from /tmp/code_below:6:innew’
from /tmp/code_below:6

Beyond that, is the posted code the same code that produced your sample
output?

44 j.client_name = cname
46 j.job_name = cname

But, cname is never set to anything before this point (or after).

9 cname_file = File.new(“XML_EXPORT/export_c_name.xml”)
14 cname_file = Document.new(cname_file)
19 puts cname_file

But, cname_file is never used after this point.

18 puts cnumbe_file

There is no cnumbe_file.

26 client_dir = @client_num.to_s + “_” + @client_name

@client_num comes from:

45 j.client_num = cnumberfile
13 cnumber_file = Document.new(cnumber_file)

@client_name comes from:

44 j.client_name = cname

Should that have been?:

44 j.client_name = cname_file
14 cname_file = Document.new(cname_file)

So, in line 26 we have something like:

26 client_dir = REXML::Document.to_s + “" + REXML::Document
26 client_dir = + "
” + REXML::Document
26 client_dir = + REXML::Document
TypeError: can’t convert REXML::Document into String

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs