I wonder whether someone can help me please.
I have the following xml file which I need to pull the values from two of the file attributes, to be more precise, ‘userid’ and ‘locationid’ for each ‘file name’. Ultimately these values will be used to determine which folders and files the user will be presented with on page load.
<?xml version="1.0" encoding="utf-8" ?>
- <files>
<file name="Test 1/Test Pic 2.jpg" source="Test_Pic_2.jpg" size="728573" originalname="Test Pic 2.jpg" thumbnail="Test_Pic_2.jpg" userid="1" locationid="1" description="No description provided" folder="Test_1" />
<file name="Test 1/stags-snow_1544533c.jpg" source="stags-snow_1544533c.jpg" size="21341" originalname="stags-snow_1544533c.jpg" thumbnail="stags-snow_1544533c.jpg" userid="1" locationid="1" description="Deer head." folder="Test_1" />
</files>
I must admit not not knowing a great deal about how to get this information, but after some searching I found a tutorial online, which I’ve adapted and have added below.
<?php
if( ! $xml = simplexml_load_file('UploadedFiles/files.xml') )
{
echo 'unable to load XML file';
}
else
{
foreach( $xml as $files )
{
echo 'userid: '.$file_name->userid.'<br />';
echo 'locationid: '.$file_name->locationid.'<br />';
}
}
?>
The problem I’m having is that when I run this, I just get the following results:
userid:
locationid:
userid:
locationid:
userid:
locationid:
The number of rows corresponds with the number of records but what I was wanting to get is the value of the field as well.
I just wondered whether someone could perhaps take a look at this and let me know where I’m going wrong.
Many thanks
I think you require something like this. (An example found at http://php.net/manual/en/simplexmlelement.attributes.php )
Hope this helps and if not please post back.