1

I am fetching XML file from remote url, but when '&' character occurs in XML, simplexml_load_file fails:

$url = 'https://domain.com/xml.php?xmlid=123;


print_r($url);

if (simplexml_load_file($url))
{
    $orderDetailsXMLData = simplexml_load_file($url);
}
else
{
    echo "Failed!";
}

XML sample file which fails is as follows:

Note, I don't have control over the source XML

1 Company1

<info>
<ccode>2</ccode>
<company>Company2</company>
</info>
<info>
<ccode>2</ccode>
<company>Company Sons & Sons</company>
</info>
</companies>

Is there any way to escape XML before importing?

Alan Kis
  • 1,790
  • 4
  • 24
  • 47
  • The example code of that file is required, so that we can test it too. – Yang Nov 16 '15 at 09:49
  • 1
    Are you asking how to write valid XML in the first place or how to repair invalid XML (that you don't have control over the source of) before handing it over to your XML parser? – Quentin Nov 16 '15 at 10:02
  • @Quentin, I don't have control over the source, I am looking for the way to repair XML before parsing. – Alan Kis Nov 16 '15 at 10:12

0 Answers0