REXML - Empty string error

Hi all,

I am parsing some XML with XPATH and REXML. A snippet is below:


e.elements[‘Questions’].text << “,” <<
e.elements[‘Offers’].text << “,” <<
e.elements[‘ID’].text << “,” <<

The ID XML tag is often an empty tag (no data in it) and this throws an
error in my script of

.rb:364:in `<<’: can’t convert nil into String (TypeError)

How do I ignore this error? I just want to take whatever is in the XML
(even if it is empty) and carry on to the next data set.

Many thanks

Stuart C. wrote in post #979927:

Hi all,

I am parsing some XML with XPATH and REXML. A snippet is below:


e.elements[‘Questions’].text << “,” <<
e.elements[‘Offers’].text << “,” <<
e.elements[‘ID’].text << “,” <<

The ID XML tag is often an empty tag (no data in it) and this throws an
error in my script of

.rb:364:in `<<’: can’t convert nil into String (TypeError)

How do I ignore this error? I just want to take whatever is in the XML
(even if it is empty) and carry on to the next data set.

Very similar question asked (and answered) within the last day:
http://www.ruby-forum.com/topic/1021053

Sorry. I did not see that.

Many thanks

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