我有一个 simplexml 对象,如下所示
<?xml version="1.0"?>
<SalesInvoices xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://api.unleashedsoftware.com/version/1">
<SalesInvoice>
<OrderNumber>100</OrderNumber>
</SalesInvoice>
<SalesInvoice>
<OrderNumber>101</OrderNumber>
</SalesInvoice>
</SalesInvoices>
我想遍历它并只打印订单号。我使用这个脚本:
foreach ($xml->SalesInvoices->SalesInvoice as $salesinvoice) {
echo "hello";
echo $salesinvoice->OrderNumber;
}
当我这样做时,我根本没有从循环中得到任何输出,即使是“你好”也不会打印出来。我究竟做错了什么?