0

I'm downloading an xml file using curl and then parsing it using simplexml_load_string() and putting it to db.

I got a problem a that the file cannot be parse, its inside <![CDATA[]]> and i notice the file has some sort of a special character that i really dont know:

special character

I'm getting the file like so:

$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);

and i'm parsing it like so:

$gpx = simplexml_load_string($myfile,'SimpleXMLElement', LIBXML_NOCDATA);

The error that I got is this:

simplexml_load_string(): Entity: line 7238: parser error : CData section not finished

How can i disregard those in to properly parse the xml file?

Thanks so much in advance.

slodeveloper
  • 242
  • 3
  • 21
  • Your XML is valid? Can you provide real XML url? – fusion3k Apr 08 '16 at 17:25
  • The xml does n t sound to be valid – cpugourou Apr 08 '16 at 17:26
  • 2
    You need to preprocess the XML string, good example of how to do that here: [How to skip invalid characters in XML file using PHP](http://stackoverflow.com/questions/3466035/how-to-skip-invalid-characters-in-xml-file-using-php) – Dan Field Apr 08 '16 at 17:27
  • fusion3k / cpugourou - It is a valid xml Dan - Thanks for this I tried it and it works great will check and test this for multiple instances if ever there will be any other special char that has the same problem. – Dhon Collera Apr 08 '16 at 18:26

0 Answers0