I am reading an xml in php using simplexml_load_file
. However while trying to load the xml it displays a list of warnings
Warning: simplexml_load_file() [function.simplexml-load-file]: <project orderno="6" campaign_name="International Relief & Development" project in /home/bluecard1/public_html/test.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/bluecard1/public_html/test.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: http://..../index.php/site/projects/:15: parser error : xmlParseEntityRef: no name in /home/bluecard1/public_html/test.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: ional Relief & Development" project_id="313" client_name="International Relief & in /home/bluecard1/public_html/test.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/bluecard1/public_html/test.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: http://..../index.php/site/projects/:15: parser error : xmlParseEntityRef: no name in /home/bluecard1/public_html/test.php on line 3
How do I rectify to remove these warnings?
(XML is generated from url http://..../index.php/site/projects
& loaded into a variable in the test.php. I dont have write priveleges to index.php)
simplexml_load_file
is throwing parsing errorparser error : xmlParseEntityRef
while trying to load the XML file from a URL.&
value instead of&
. It is quite possible that there are other errors which aren't obvious at this point of time.simplexml_load_file
function, but it looks like we don't have any control over how the XML is created.simplexml_load_file
to process an invalid XML file. It does not leave us with many options, other than fixing the XML file itself.Convert Invalid XML to Valid XML. It can be done using
PHP tidy extension
. Further instructions can be found from http://php.net/manual/en/book.tidy.phpOnce you are sure that the extension exists or is installed, please do the following.
The developer should try to compare the invalid XML with a valid XML (generated by tidy), to see there are no adverse side effects after using tidy. Tidy does an extremely good job of doing it correctly, but it never hurts to see it visually and to be 100% sure. In our case it should be as simple as comparing $xml with $tidy.
This solve my problème:
I use a combined version :