我有这个 XML:
<?xml version="1.0" encoding="UTF-8"?>
<data>
<header>
<export_time>2012-08-28 08:13:36</export_time>
<file_name>nameasd</file_name>
</header>
<shipping>
<shipping_number>some data</shipping_number>
<location_id>some data</location_id>
<status>DONE</status>
<shipping_line>
<article id="1257" />
<article id="1177" >
<product>5500070000126273</product>
<product>5500070000126264</product>
<product>5500070000126255</product>
<product>5500070000126246</product>
<product>5500070000126237</product>
</article>
</shipping_line>
</shipping>
</data>
ii 可以像这样访问数据:
$shipping_number_array = $xml->xpath('/data/shipping/shipping_number');
$location_id_array = $xml->xpath('/data/shipping/location_id');
$shipping_status_array = $xml->xpath('/data/shipping/status');
$shipping_number = $shipping_number_array[0];
$location_id = $location_id_array[0];
$status = $shipping_status_array[0];
现在我想检查article
元素是否有任何子元素,如果是,则将它们放入数组中。
这似乎不起作用,我收到错误:在非对象上调用成员函数 hasChildren()。
if ($article_array->hasChildren()) {
error_log('has children');
}