【发布时间】:2018-12-26 14:33:54
【问题描述】:
我有一个 xml,并且可以在使用 simplexml_load_file 加载 xml 后使用 xpath 获取包含我需要的数据的数组。
我试过这样:Access @attributes data in SimpleXMLElement in PHP
使用我的 XML 到数组我仍然无法访问节点,请有人检查我的代码:谢谢
$result2 = $xml->xpath("//file[@Catid='151']");
给出这个数组: 数组
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[path] => export/freexml.int/DE/4757.xml
[Product_ID] => 4757
[Updated] => 20170902053143
[Quality] => ICECAT
[Supplier_id] => 3
[Prod_ID] => TT34MUK
[Catid] => 151
[On_Market] => 1
[Model_Name] => THINKPAD T23 P3-1.13G
[Product_View] => 12655
[HighPic] => http://images.icecat.biz/img/norm/high/4757-6880.jpg
[HighPicSize] => 4138
[HighPicWidth] => 200
[HighPicHeight] => 150
[Date_Added] => 20050715000000
[Limited] => No
)
[EAN_UPCS] => SimpleXMLElement Object
(
[EAN_UPC] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Value] => 3606503209062
[IsApproved] => 0
)
)
)
[Country_Markets] => SimpleXMLElement Object
(
[Country_Market] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Value] => LU
)
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[path] => export/freexml.int/DE/41895.xml
[Product_ID] => 41895
[Updated] => 20170902052843
[Quality] => ICECAT
[Supplier_id] => 7
[Prod_ID] => LX.T2606.067
[Catid] => 151
[On_Market] => 1
[Model_Name] => TRAVELMATE 432LC P4-2.53G
[Product_View] => 12056
[HighPic] => http://images.icecat.biz/img/norm/high/41895-65.jpg
[HighPicSize] => 14404
[HighPicWidth] => 330
[HighPicHeight] => 290
[Date_Added] => 20050715000000
[Limited] => No
)
[Country_Markets] => SimpleXMLElement Object
(
[Country_Market] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Value] => DE
)
)
)
)
如何访问“路径”等值?我有问题 [0] => SimpleXMLElement Object 那么节点的名称是什么?
echo (string)$result2->0[0]->attributes()->path;
没用.....
谢谢
【问题讨论】:
标签: php xml xpath attributes simplexml