1

When requesting data from my remote server it responds with a value inside a node with the following token , making the parsing process to fail. I manually removed the guilty string and it started working.

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
...
    <sFName>Bradley</sFName>
    <sLName>L&#x1E;ibbra</sLName>
...

Token: &#x1E;

The error raised by Savon is:

Savon::InvalidResponseError: Unable to parse response body:

kjhughes
  • 106,133
  • 27
  • 181
  • 240
damuz91
  • 1,461
  • 2
  • 21
  • 37

2 Answers2

1

&#x1E; (aka INFORMATION SEPARATOR TWO) is not an allowed character in XML :

[2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

Therefore your data is not XML, and any conformant XML processor must report an error such as the one you received.

You must repair the data by removing any illegal characters by treating it as text, not XML, manually or automatically before using it with any XML libraries.

See also How to parse invalid (bad / not well-formed) XML?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
0

My original question was around Savon ruby gem. I sorted this out by changing the default response parser to :rexml. It now parses the invalid character and does not raises an exception.

:itssomething:

But right answer would be to parse the malformed XML or ask the provider to fix it. Thanks @kjhughes

damuz91
  • 1,461
  • 2
  • 21
  • 37