I use simplexml_load_string() to parse a XML API response.
$lien = "http://myresponseurl";
$page = simplexml_load_string($this->get_data($lien));
Everythink is working good, except in this case:
<libdivision><1500 Poule H</libdivision>
Where the text to get back should be "<1500 Poule H" but, the "<" caractère is also in XML the symbol of an opening tag...
What should I do to get back "<1500 Poule H" without any errors ?
Warning: simplexml_load_string(): Entity: line 4: parser error : StartTag: invalid element name
Warning: simplexml_load_string(): <libdivision><1500 Poule G</libdivision>
Warning: simplexml_load_string(): ^
Thanks for help
<libdivision><1500 Poule H</libdivision>
This is invalid XML. The provider of the API should fix this, this is a clear bug in the API and a client is not responsible for working with malformed data. There are two options:
Wrap it in a CDATA field:
<libdivision><![CDATA[<1500 Poule H]]></libdivision>
Or encode the symbol:
<libdivision><1500 Poule H</libdivision>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With