Forum: Ruby REXML and entities

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Pawel S. (Guest)
on 2006-03-31 04:52
(Received via mailing list)

I've been trying to use REXML to process an XML file with entities,
but I can't seem to get it to leave my entities alone even with the
:raw context set. The simplified example looks something like this:

# song.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Song [
<!ELEMENT Song (lyric*)>
<!ELEMENT lyric (#PCDATA)>
<!ENTITY convoy "we got a great big convoy">
<!ENTITY rubberduck "ain't she a beautiful sight">
# script.rb:
doc ='song.xml', 'r'), { :raw => :all }

doc.elements.each('Song/lyric') do |lyric|
  puts lyric.raw # This prints 'true'
  puts lyric.text # This always has its entities decoded!
# output:
we got a great big convoy
ain't she a beautiful sight
# desired output:

When I take out the { :raw => :all } part, the entry.raw line returns
nil, but the output isn't changed. Am I misunderstanding how this is
supposed to work, or is it broken? How can I get the entities back in
an unencoded form? This is driving me crazy.


This topic is locked and can not be replied to.