我从 Google 返回了以下 DOMNodeList 对象,我需要对其进行解析。
我将其解析为一个 DOMElement 对象数组,每个警告对应一个:
$new_product = _GSC_AtomParser::parse($resp->body);
$elements = $new_product->getWarnings();
$warnings = array();
foreach ($elements as $element):
$warnings[] = $element;
endforeach;
然后我需要解析这些 DOMElement 对象以获取警告:
[0] => DOMElement Object
(
[tagName] => sc:warning
[schemaTypeInfo] =>
[nodeName] => sc:warning
[nodeValue] => validation/missing_recommendedShoppinggoogle_product_categoryWe recommend including this attribute.
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] => http://schemas.google.com/structuredcontent/2009
[prefix] => sc
[localName] => warning
[baseURI] => /home/digit106/dev/public_html/manager/
[textContent] => validation/missing_recommendedShoppinggoogle_product_categoryWe recommend including this attribute.
)
我想把它格式化成这样的数组:
[warnings] => Array
(
[0] => Array
(
[domain] => Shopping
[code] => validation/missing_recommended
[location] => google_product_category
[internalReason] => We recommend including this attribute.
)
)
但所有这些数据似乎都嵌套在 nodeValue 或 textContent 中。
我该怎么解析这个?