私はxmlファイルを解析していますが、タグ( ":g")に関するいくつかの問題を抱えています、私は情報、彼のコンテンツにアクセスできません、問題は私がカテゴリを取得しようとするときです複数のカテゴリー。すべてのgoogleタグを取得していますxml
のxml:私は、たとえば使用してカテゴリを取得してみてください
<item>
<g:id>4011700742288</g:id>
<title><![CDATA[4711 Acqua Colonia Blood Orange & Basil Eau de Cologne 170ml]]></title>
<link><![CDATA[https://url/asdasd.html]]></link>
<g:image_link><![CDATA[https://url/media/catalog/product/4/7/4711-acqua-colonia-blood-_2.jpg]]></g:image_link>
<g:price>34.86 EUR</g:price>
<g:product_type><![CDATA[Mulher]]></g:product_type>
<g:product_type><![CDATA[Homem]]></g:product_type>
<g:product_type><![CDATA[Unisexo]]></g:product_type>
</item>
は:
$categories = $item->children('g', TRUE)->product_type;
しかし、それは唯一の最初のカテゴリをもたらすには、カテゴリの残りの部分をgetingされていません。 上記のデータを取得する方法のコード例です。 例:
foreach($rss->channel->item as $item) {
$categories = $item->children('g', TRUE)->product_type;
// bringing in to array <content:encoded> items from SimpleXMLElement Object()
$content = xmlObjToArr($item->children('content', true)->encoded);
echo $categories . PHP_EOL;
return;
}
function xmlObjToArr($obj) {
$namespace = $obj->getDocNamespaces(true);
$namespace[NULL] = NULL;
$children = array();
$attributes = array();
$name = strtolower((string)$obj->getName());
$text = trim((string)$obj);
if(strlen($text) <= 0) {
$text = NULL;
}
// get info for all namespaces
if(is_object($obj)) {
foreach($namespace as $ns=>$nsUrl) {
// atributes
$objAttributes = $obj->attributes($ns, true);
foreach($objAttributes as $attributeName => $attributeValue) {
$attribName = strtolower(trim((string)$attributeName));
$attribVal = trim((string)$attributeValue);
if (!empty($ns)) {
$attribName = $ns . ':' . $attribName;
}
$attributes[$attribName] = $attribVal;
}
// children
$objChildren = $obj->children($ns, true);
foreach($objChildren as $childName=>$child) {
$childName = strtolower((string)$childName);
if(!empty($ns)) {
$childName = $ns.':'.$childName;
}
$children[$childName][] = xmlObjToArr($child);
}
}
}
return array(
'name'=>$name,
'text'=>$text,
'attributes'=>$attributes,
'children'=>$children
);
}
あなたが実際にコードで 'xmlObjToArr'関数の結果を使用していないので、表示すると、[編集]し、あなたの例から削除することができます。私の助言はあなたのコードからもそれを削除し、SimpleXMLオブジェクトを使用することを意図したものを使用することです。 – IMSoP