I'm using REXML to parse through some XML data sent via POST. The XML is sent correctly formatted with "&" sent as "&
". However, when I try to parse it, I had problems like the &
becoming & and throwing an error. I fixed with gsub, but now it says #<REXML::ParseException: Missing end tag for 'br'
Anyone have any experience parsing through XML sent via POST on Rails?
def parse
xml = params["xml_data"]
xml = xml.gsub(/&/,"&")
doc, posts = REXML::Document.new(xml), []
end
The problem most likely is that you send html istead of xml and html isn't valid xml - don't try to use regexp or xml processors for its parsing. In your case you likely encountered <br> tag (not <br /> pay attention) - that perfectly ok for html. Try to use Nokogiri gem for html parsing