I have the following XML file :
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<item>
[...]
<wp:postmeta>
<wp:meta_key>_wp_old_slug</wp:meta_key>
<wp:meta_value><![CDATA[item-1-slug]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_yoast_wpseo_title</wp:meta_key>
<wp:meta_value><![CDATA[item-1-title]]></wp:meta_value>
</wp:postmeta>
[...]
</item>
<item>
[...]
<wp:postmeta>
<wp:meta_key>_wp_old_slug</wp:meta_key>
<wp:meta_value><![CDATA[item-2-slug]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_yoast_wpseo_title</wp:meta_key>
<wp:meta_value><![CDATA[item-2-title]]></wp:meta_value>
</wp:postmeta>
[...]
</item>
</channel>
</rss>
I'm looping through my items with
$xmlurl = file_get_contents($xmlFile);
$xml = simplexml_load_string($xmlurl, null, LIBXML_NOCDATA);
$items = $xml->channel->item;
foreach( $items as $item ) {
}
Inside this loop, i'd like to read the value of the sibling of the <wp:meta_key>_yoast_wpseo_title</wp:meta_key>
node. For example, for item 1, i'd like to get "item-1-title".
I probably have to use xpath, but i really dont know how to proceed.
How can I do this ?
rss
). If it is not there, something will need to be changed. (I believe using$item->registerXPathNamespace
). – Harass