php - "Comment not terminated" XML parsing error in Box API response

961

For months I've been running the "Box Rest Client" lib by Angela R that employs the following code to parse curl responses from the box API:

$xml = simplexml_load_string($res);

Today, after the code loops through dozens of request/responses I generate this following error:

ErrorException [ Warning ]: simplexml_load_string(): Entity: line 9: parser error : Comment not terminated

This happened in 2 straight attempts to run the code - and now seems to have gone away without any changes to anything.

Interested if anyone knows what is up with that?

I have put a catch for this case if its useful to anyone using this lib (for the next month or so before its deprecated by box api 2.0)

private function parse_result($res) {
 try {
      $xml = simplexml_load_string($res);
  $json = json_encode($xml);
  $array = json_decode($json,TRUE);     
  return $array;
 } catch (Exception $e){    
    $error = 'xml parsing error: '. $e->getMessage(). "<br>";
  return array('status' => $error );
 }
}
156

Answer

Solution:

It's possible it is related to including two minus signs -- inside of an HTML comment. For example:

<!-- this is my comment--but not a very good one. -->

The two dashes in the middle of the comment causes problems with the parser.

People are also looking for solutions to the problem: php - Removing a form field (select) when form submits

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.