I'm trying to put some data from an XML file on my site. The code I found that I'm trying to use is included below. I have the following problem:
This code scans an entire directory for XML files, and I only need it to access one specific XML file (ideally on a remote server, although I understand from W3Schools that XML security prevents remote XML parsing. How do I change this to reference a specific file called "data.xml"?
<?php
$ext = 'xml';
$dirname = "data/";
$files = scandir($dirname);
foreach($files as $file){
if(($file != ".") and ($file != "..")){
$fileChunks = explode(".", $file);
if($fileChunks[1] == $ext){
$title = $file;
$doc = new DOMDocument();
if($doc && $doc->load($file)){
$xpath = new DOMXPath($doc);
$query = "/info/name";
$entries = $xpath->query($query);
if($entries->length > 0){
$title = $entries->item(0)->nodeValue;
}
}
echo '<div class="info"><a href="#" onclick=\'open("pages/' . $file . '","","width=300,height=250"); return false;\'>' . $title . '</a></div>
';
}
}
}
The XML file I'm parsing looks like this (in the data directory):
<?xml version="1.0"?>
<info>
<name>Some Guy</name>
<phone>555-555-5555</phone>
<address>1313 Elm St</address>
<city>Sometown</city>
<state>OK</state>
<zip>77777</zip>
<email>email@mail.net</email>
</info>