Keith Fahlgren
8/31/2007 8:19:00 PM
On 8/31/07, John Butler <johnnybutler7@gmail.com> wrote:
> When reading in the site element from my xml file using rexml it seems
> to be chopping the rest of the text off after the first <br/>
>
> The value in the XML file is below
> <Site>123 street<br/>amstown<br/>amserland</Site>
>
> element = REXML::XPath.first(doc, '//Site')
>
I'd suggest using a bit more XPath, both text() and a each {} to
iterate through the text nodes (which are distinct):
$ irb -r rexml/document --prompt xmp
a = REXML::Document.new("<Site>123 street<br/>amstown<br/>amserland</Site>")
# => <UNDEFINED> ... </>
REXML::XPath.first(a, '//Site').text
# => "123 street"
REXML::XPath.first(a, '//Site/text()').to_s
# => "123 street"
REXML::XPath.each(a, '//Site/text()') {|el| puts el}
123 street
amstown
amserland
# => ["123 street", "amstown", "amserland"]
HTH,
Keith