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/>
Not quite. It gives you the *first* text element.
The value in the XML file is below
<Site>123 street<br/>amstown<br/>amserland</Site>
element = REXML::XPath.first(doc, '//Site')
puts element.text #shows 123 Street
How can i get the full data and once i have it i can remove the <br/> I
cant find any information on this???
You can't find any specific info because there isn't anything specific.
You have an XML element that contains a text node, an empty element named
br, another text node, another empty element named br and another text
node. In the XML world, <br/> is a node like any other.
The REXML::Element.texts method is what you are looking for:
The assert_xpath plugin wraps that up in this convenient method:
class REXML::Element
def inner_text
return self.each_element( './/text()' ){}.join( '' )
end
end
...
def test_absolve_breaks
a = REXML::Document.new("<Site>123
street<br/>amstown<br/>amserland</Site>")
assert_equal "123 streetamstownamserland", a.inner_text
end
Come to think of it, that's not terribly programmer-friendly! Let's upgrade
it a little...