PHP simplexml and xpath
Posted
by FFish
on Stack Overflow
See other posts from Stack Overflow
or by FFish
Published on 2010-05-16T14:15:16Z
Indexed on
2010/05/16
14:20 UTC
Read the original article
Hit count: 463
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?
© Stack Overflow or respective owner