具有动态路径的Simplexml对象

时间:2015-06-16 07:41:47

标签: php simplexml

我想在simplexml对象中动态定义fetched属性的属性路径。我试过跟随,但它没有用。这可能在PHP吗?

$xml = $z->readOuterXML();
$item = simplexml_load_string($xml);

// This works
echo $item->attribute1->attribute2->attribute3;

// However I want to dynamically define path for attribute like this, this example is not really working
$path = "attribute1->attribute2->attribute3";
echo $item->{$path};

0 个答案:

没有答案