使用php从xpath之后的simplexml\u load\u文件中从数组中获取@attributes

使用php从xpath之后的simplexml\u load\u文件中从数组中获取@attributes,php,xml,xpath,attributes,simplexml,Php,Xml,Xpath,Attributes,Simplexml,我有一个xml,在用simplexml\u load\u文件加载xml之后,我可以用xpath获取包含所需数据的数组 我这样试过: 使用我的XML to数组,我仍然无法访问节点,请有人检查我的代码:谢谢 $result2 = $xml->xpath("//file[@Catid='151']"); 这就给了这个数组: 排列 如何访问“路径”等值?我的电脑有问题 [0]=>SimpleXMLElement对象那么节点的名称是什么 echo (string)$result2->0[0]

我有一个xml,在用simplexml\u load\u文件加载xml之后,我可以用xpath获取包含所需数据的数组

我这样试过:

使用我的XML to数组,我仍然无法访问节点,请有人检查我的代码:谢谢

$result2 = $xml->xpath("//file[@Catid='151']");
这就给了这个数组: 排列

如何访问“路径”等值?我的电脑有问题 [0]=>SimpleXMLElement对象那么节点的名称是什么

echo (string)$result2->0[0]->attributes()->path;
没用


谢谢

尽管使用XML检查会更容易,但您可能会发现正确的表示法是

echo (string)$result2[0]->attributes()->path;
这假设您需要XPath找到的第一个项

你也可以找到

echo (string)$result2[0]['path'];
有效(但并不总是有效)

echo (string)$result2[0]['path'];