bravo14 Posted October 19, 2017 Share Posted October 19, 2017 Hi I am trying to use SimpleXML to parse the wordpress export XML file, but when parsing it I am not able to view all elements of the file. Each 'item' is made up in the XML as follows <item> <title></title> <link>http://www.dannykingracing.co.uk/?p=396</link> <pubDate>Fri, 21 Oct 2016 10:48:48 +0000</pubDate> <dc:creator><![CDATA[@dmin]]></dc:creator> <guid isPermaLink="false">http://46.32.240.33/dannykingracing.co.uk/?p=396</guid> <description></description> <content:encoded><![CDATA[ ]]></content:encoded> <excerpt:encoded><![CDATA[]]></excerpt:encoded> <wp:post_id>396</wp:post_id> <wp:post_date><![CDATA[2016-10-21 11:48:48]]></wp:post_date> <wp:post_date_gmt><![CDATA[2016-10-21 10:48:48]]></wp:post_date_gmt> <wp:comment_status><![CDATA[closed]]></wp:comment_status> <wp:ping_status><![CDATA[closed]]></wp:ping_status> <wp:post_name><![CDATA[396]]></wp:post_name> <wp:status><![CDATA[publish]]></wp:status> <wp:post_parent>0</wp:post_parent> <wp:menu_order>1</wp:menu_order> <wp:post_type><![CDATA[nav_menu_item]]></wp:post_type> <wp:post_password><![CDATA[]]></wp:post_password> <wp:is_sticky>0</wp:is_sticky> <category domain="nav_menu" nicename="menu"><![CDATA[Menu]]></category> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_type]]></wp:meta_key> <wp:meta_value><![CDATA[post_type]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_menu_item_parent]]></wp:meta_key> <wp:meta_value><![CDATA[0]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_object_id]]></wp:meta_key> <wp:meta_value><![CDATA[395]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_object]]></wp:meta_key> <wp:meta_value><![CDATA ]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_target]]></wp:meta_key> <wp:meta_value><![CDATA[]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_classes]]></wp:meta_key> <wp:meta_value><![CDATA[a:1:{i:0;s:0:"";}]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_xfn]]></wp:meta_key> <wp:meta_value><![CDATA[]]></wp:meta_value> </wp:postmeta> <wp:postmeta> <wp:meta_key><![CDATA[_menu_item_url]]></wp:meta_key> <wp:meta_value><![CDATA[]]></wp:meta_value> </wp:postmeta> </item> however when parsing it all I get is [title] => SimpleXMLElement Object ( ) [link] => http://www.dannykingracing.co.uk/?p=396 [pubDate] => Fri, 21 Oct 2016 10:48:48 +0000 [guid] => http://46.32.240.33/dannykingracing.co.uk/?p=396 [description] => SimpleXMLElement Object ( ) [category] => Menu the code I am using is: <?php $items = $xml->channel->item; foreach ($items as $item){ print_r($item); } ?> My question is how can I view all of the elements of the XML file, I am clearly missing somethin I just can't figure it out. Link to comment Share on other sites More sharing options...
requinix Posted October 19, 2017 Share Posted October 19, 2017 All the stuff is there but it will only show you the nodes in the current namespace, which you can change using children() or attributes(). For example, echo "Link = ", $item->link, "\n"; $wpitem = $item->children("???"); echo "Post ID = ", $wpitem->post_id, "\n";Replace the ??? with the xmlns:ns that's somewhere in the feed - probably at the root. (Doing it with the "wp" prefix is possible but not as good.) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.