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

···

--
Posted via http://www.ruby-forum.com/.

Stuart Clarke 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:

···

--
Posted via http://www.ruby-forum.com/\.

Sorry. I did not see that.

Many thanks

···

--
Posted via http://www.ruby-forum.com/.