我已經被從谷歌返回以下的DOMNodeList對象,我需要通過它來解析。解析的DOMNodeList成數據我可以很容易地格式化PHP
我解析成一個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.
)
)
但是,所有這些數據似乎是neste d放入nodeValue或textContent中。
如何赫克我分析了這一點?
http://php.net/DOMElement#86596 –