tags:

views:

49

answers:

1

I have an XML file like this:

<?xml version="1.0" encoding="UTF-8"?>
<gallery>
    <album tnPath="tn/" lgPath="imm/" fsPath="iml/" >
        <img src="001.jpg" />
        <img src="002.jpg" />
    </album>
</gallery>

I am reading the file with:

$xmlFile = "xml.xml";
$xmlStr = file_get_contents($xmlFile . "?" . time());
$xmlObj = simplexml_load_string($xmlStr);

Now I am rebuilding the XML file and would like to save the album node with it's attributes in a var I was thinking with xpath:

// these all return arrays with the images...
// echo $xmlObj->xpath('/gallery/album@tnPath');
// echo $xmlObj->xpath('//album[@tnPath]');
// echo $xmlObj->xpath('//@tnPath');

But that doesn't seem to work? Any help?

A: 

$xmlObj->xpath('/gallery/album') gives your the album node(s).

ThiefMaster
yes, but I want the attributes from the <album> node..
FFish
Ok, I got it working with $foo = $xmlObj->xpath('//@tnPath'); echo $foo[0];
FFish