Jump to content

SimpleXML not showing all elements of XML file


Recommended Posts



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



        <pubDate>Fri, 21 Oct 2016 10:48:48 +0000</pubDate>
        <guid isPermaLink="false"></guid>
        <content:encoded><![CDATA[ ]]></content:encoded>
        <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>
        <category domain="nav_menu" nicename="menu"><![CDATA[Menu]]></category>



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] => [description] => SimpleXMLElement Object ( ) [category] => Menu


the code I am using is:



  $items = $xml->channel->item;
  foreach ($items as $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

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

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.