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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.