I am getting an error on trying to load a XML file using PHP when I use the Physical path of the file. When the XML file is located in the same directory as code file I do not get a problem. Code is given below
<?php
$xml=simplexml_load_file(realpath('D:\XMLeq.xml')) or die("Error: Cannot create object");
print_r($xml);
?>
Any help will be appreciated.
Regards, Rahul
I can't offer advice on simplxml but the following, using DOMDocument, does work.
<?php
$path=realpath('C:\wwwroot\files\xml\bbc_rss.xml');
if( $path ){
libxml_use_internal_errors( true );
$dom=new DOMDocument;
$dom->standalone=true;
$dom->validateOnParse=false;
$dom->strictErrorChecking=false;
$dom->recover=true;
$dom->formatOutput=false;
$dom->load( $path );
libxml_clear_errors();
echo '<pre>', print_r( $dom->saveXML() ,true ),'</pre>';
$dom=null;
} else {
echo 'unable to find the xml file.';
}
?>
When I tried with a bad xml ( ie: one that is poorly formed or considered invalid for some reason ) file nothing was displayed but with xml files I know to be ok it was fine. If you don't wish to use the DOMDocument method then might I suggest trying with a known xml file from the interwebs as a test?