Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity

Tags:

php

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "USD_en_productdata/USD_en_productdata.xml"

the code

$src=simplexml_load_file("USD_en_productdata/USD_en_productdata.xml");

foreach($src->ProductItem as $i){
}
like image 267
Ahmed Abada Avatar asked Mar 19 '12 14:03

Ahmed Abada


2 Answers

Try to pass full directory path if you are trying to load xmls held at your server

simplexml_load_file($_SERVER['DOCUMENT_ROOT'].'/uproYourFoldet/USD_en_productdat/USD_en_productdata.xml')

or if you want to access xml by http protocol you will need to set allow_url_fopen ON in php.ini or

ini_set('allow_url_fopen ','ON');

in your code. or you can also do this if you are using php version <5

$temp = file_get_contents($url);
 $XmlObj = simplexml_load_string($temp); 
like image 51
Rupesh Patel Avatar answered Oct 22 '22 09:10

Rupesh Patel


Looks like your path might not be correct.

In my experience, it's best to surround simplexml_load_file and subsequent functions with if statements with file_exists(...) as the condition.

So in your case:

if(file_exists($_SERVER['DOCUMENT_ROOT'].'/yourPathToFile/...')) {
simplexml_load_file($_SERVER['DOCUMENT_ROOT'].'/urltoYourFolder/USD_en_productdat/USD_en_productdata.xml')
}

EDIT: spelling

like image 44
Martin Sheeks Avatar answered Oct 22 '22 10:10

Martin Sheeks