0

Im connecting to an external API which returns messages with the character

Response:

<daoapi>
  <status>FEJL</status>
  <fejlkode>520</fejlkode>
  <fejltekst>Fejl ved opslag: Der er fejl i input parametre:&#13;
Husnummer mangler eller er ikke numerisk&#13;
</fejltekst>
</daoapi>

It's in danish, but you can see the characters occuring twice

How can I escape this?

Tarlen
  • 3,657
  • 8
  • 30
  • 54

2 Answers2

2

You should parse the XML response with Nokogiri, it handles entity conversion.

require 'nokogiri'

response = <<-XML
<daoapi>
  <status>FEJL</status>
  <fejlkode>520</fejlkode>
  <fejltekst>Fejl ved opslag: Der er fejl i input parametre:&#13;
Husnummer mangler eller er ikke numerisk&#13;
</fejltekst>
</daoapi>
XML

doc = Nokogiri::XML(response)
doc.at_xpath('//fejltekst').text
#=> "Fejl ved opslag: Der er fejl i input parametre:\r\nHusnummer mangler eller er ikke numerisk\r\n"
Stefan
  • 109,145
  • 14
  • 143
  • 218
0

That's no weird character but an ASCII-encoded character interpretable as an Carriage Return. Check AsciiTable or any other reference.

You can either reencode you output to change it to \n, a html entity or probably leave it like that as it will cause no harm.

dgilperez
  • 10,716
  • 8
  • 68
  • 96