Tôi gặp một chút rắc rối khi phân tích cú pháp XML từ phản hồi thanh toán của google. XML sắp đến từ máy chủ google nên không có vấn đề gì với chính XML.SimpleXmlElement và XPath, nhận mảng trống()
Tôi muốn giữ tất cả các thẻ thông báo đơn đặt hàng mới
Tôi đã thử điều này nhưng nhận được một mảng trống() trả về mọi lúc.
$xml = new SimpleXmlElement($raw_xml);
$notifications = $xml->xpath('notifications');
$notifications = $xml->xpath('/notification-history-response/notifications/new-order-notification');
$notifications = $xml->xpath('//new-order-notification');
Một snipet XML (Chỉ cần đầu)
<notification-history-response xmlns="http://checkout.google.com/schema/2" serial-number="c5cda190-0eb1-4f91-87cd-e656e5598d38">
<notifications>
<new-order-notification serial-number="271578974677716-00001-7">
<buyer-billing-address>
<address1>19 sandbox st</address1>
<address2></address2>
* XML sắp xuất phát từ máy chủ google nên không có vấn đề gì với chính XML. * Có, google gần giống như @Jon Skeet trong lĩnh vực đó. XML của họ được định dạng đúng theo định nghĩa. ;-) – LarsH