0

I'm using REXML to parse through some XML data sent via POST. The XML is sent correctly formatted with "&" sent as "&amp;". However, when I try to parse it, I had problems like the &amp; 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(/&/,"&amp;")

doc, posts = REXML::Document.new(xml), []
end
Brian Weinreich
  • 7,692
  • 8
  • 35
  • 59

1 Answers1

1

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

WarHog
  • 8,622
  • 2
  • 29
  • 23
  • Yeah I just discovered Nokogiri. Its so nice. Excited to try it out. I just installed the gem and added it to my gemfile, but am getting no such file to load -- nokogiri ... now off to figuring why it wont load the nokogiri gem! – Brian Weinreich Oct 26 '11 at 21:04