开发者

PHP simplexml and xpath

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜