Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error occured while parsing an XML document

I am getting this error while service call which returns XML response. I am unable to find out and this Issue is recurring for some time.

Error:

An error occured while Parsing an XML document.
The element type "hr" must be terminated by the matching end-tag "</hr>"

(Update from comments)

I am getting XML from IP Address Geolocation XML API. Below is the XML response. It's correct by most times I get that error.

XML response:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <statusCode>OK</statusCode>
  <statusMessage>
  </statusMessage>
  <ipAddress>x.x.x.x</ipAddress>
  <countryCode>US</countryCode>
  <countryName>UNITED STATES</countryName>
  <regionName>NEW YORK</regionName>
  <cityName>NEW YORK CITY</cityName>
  <zipCode>10112</zipCode>
  <latitude>40.7143</latitude>
  <longitude>-72.006</longitude>
  <timeZone>-03:00</timeZone>
</Response>
like image 377
Sks Avatar asked Mar 22 '23 16:03

Sks


1 Answers

There are probably issues with the request being given to the service or with the service itself, and the service is returning, not a nice XML message as expected, but instead a HTML error page which includes an unterminated horizontal rule (hr) element. Examine the HTML for clues as to what you might need to do differently with your request. Be sure to consider whether service is expecting you to POST to its endpoint rather than GET. Check the media type of your Accept header. Also check authentication. Finally, make sure you're not re-using a buffer improperly such that there's residual HTML before or after the proper XML response from the service.

like image 59
kjhughes Avatar answered Apr 01 '23 21:04

kjhughes