parsing xml document using cURL
I am trying to parse an xml document I created in a php file and outputted using
echo $xmlMysql->saveXML();
using cURL I send the information over, but when I try and parse it through using the following code.
$xmlDoc = downloa开发者_如何学JAVAd_page($url);
$dom = new DomDocument();
$dom->load($xmlDoc);
echo $dom->saveXML();
I get this error message,
<b>Warning</b>: I/O warning : failed to load external entity
^
any help with this would be much appreciated
if $xmlDoc is a string of XML that you're getting from an HTTP request, try using the loadXML method instead of just load method of your DomDocument object.
You can do
$dom = new DomDocument()
$dom->resolveExternals = false;
//...
to prevent external entities from being resolved. Of course, you may want to investigate which external entities are not being read. See also libxml_disable_entity_loader
.
Try the following code:
$dom = dom_import_simplexml(simplexml_load_string($response))->ownerDocument;
$dom->formatOutput = true;
echo '<PRE style="color:#000066;padding:10px;text-align:left">',htmlspecialchars($dom->saveXML()),'</PRE>';
精彩评论