Parsing XML: always 'syntax error'

G

gtcc2009

Hi there,
I'm trying to parse a document using the code from the book The Ruby
Way. And the program always output 'syntax error in line 1', I have
tried with a non-exist xml file, an existing but invalid formatted one
and an existing and valid formatted one. All have the same outputs. The
xml file is in the same folder with the ruby file.

require 'xmltreebuilder'
def setup_dom(path)
builder = XML::DOM::Builder.new(0)
builder.setBase(".") # have tried ./ has well
begin
puts path
xmltree = builder.parse(path, true)
rescue XMLParserError => err
line = builder.line
print "#{ $0} : #{ $!} (in line #{ line} )\n"
exit 1
end
xmltree.documentElement.normalize
return xmltree
end

Can anyone help me with this?

Thanks,

Dor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top