REXML code no longer works

S

Scott Rubin

Ok,
So I have a program that uses REXML. It works. I have working code.
But I think something in rexml changed and now my code is broken.
Either that or my code is broken in such a way that I cannot figure out
the problem.

What I'm doing is storing xml files then loading the data into an
object. The code is equivalent to this.

require 'rexml/document'
include REXML

cfg = File.new( "configfile.xml" )
config = Document.new( cfg )
myObj = myObject.new( config.elements[ "//idtag" ] )

If I try just doing

print config.elements[ "//idtag" ]

I get the same error. so it must be caused by something in the Document
object, maybe its not being made right? Here is the backtrace.


/usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:75:in `internal_parse':
undefined method `node_type' for #<REXML::Element:0x40425edc>
(NoMethodError)
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:73:in
`delete_if'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:73:in
`internal_parse'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:51:in `match'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:303:in `d_o_s'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:301:in
`each_index'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:301:in `d_o_s'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:294:in
`descendant_or_self'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:220:in
`internal_parse'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:51:in `match'
from /usr/lib/ruby/site_ruby/rexml/xpath_parser.rb:34:in `parse'
from /usr/lib/ruby/site_ruby/rexml/xpath.rb:28:in `first'
from /usr/lib/ruby/site_ruby/1.8/rexml/element.rb:844:in `[]'



It says that node_type is undefined. However, if I look in
/usr/lib/ruby/site_ruby/rexml/element.rb I can plainly see that
node_type is indeed defined. I triple checked the XML to make sure it
was valid. And no matter which xpath I use it still breaks. Ideas anyone?

-Scott
 
S

Sean Russell

Scott Rubin said:
So I have a program that uses REXML. It works. I have working code.
But I think something in rexml changed and now my code is broken.
Either that or my code is broken in such a way that I cannot figure out
the problem.

Yikes! This is not good. Can you tell me which version you WERE
using that worked, and which version that you're NOW using that
doesn't?

I'll check this out soon.

--- SER
 
S

Sean Russell

Scott Rubin said:
Ok,
So I have a program that uses REXML. It works. I have working code.
But I think something in rexml changed and now my code is broken.
Either that or my code is broken in such a way that I cannot figure out
the problem.

I've applied Kou's patch, since it is as good as any.

FYI, the constructor that takes a Source as an argument has been
deprecated, and is no longer supported. This was not documented, so
my bad. Kou's patch will get your code working, but I'm not going to
extend it to make it more complete.

Please do not use the constructor this way any longer. If you
absolutely need to parse a doctype out of an XML document, use:

d = Document.new( source )
doctype = d.doctype

rather than:

doctype = DocType.new( source )

This backwards-compatability patch will be in Ruby CVS by the end of
day, and will be in REXML 3.0.7.

Thanks.

--- SER
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top