Jump to content

[SOLVED] Help parsing XML?


woolyg

Recommended Posts

Hi, Could someone maybe point out how I would do this?

 

I'm trying to display the article:uid from the following XML string:

 

<item>
<title><![CDATA[Headline here]]></title>
<link>http://www.ext_site.com/page/Headlines/0,,12306~1347132,00.html</link>
<pubDate>
Sat, 19 Jul 2008 10:50:00 +0100
</pubDate>
<description><![CDATA[Description goes here]]></description>

<article:uid>1347132</article:uid>

</item>

 

 

I'm using:

<?php
foreach ($xml->xpath('//item') as $item) {

$title = $item->title;
$description = $item->description;
$guid = $item->xpath('//article:uid');

echo "<a href='$link'>".$guid." - ".$title."</a><br />".$description."<br />";
}
?>

 

.. but the guid isn't displaying, it's only saying "Array" - can anyone help me on how to extract the 'article:uid' from the string?

 

All help appreciated,

Thanks - WoolyG

Link to comment
https://forums.phpfreaks.com/topic/115644-solved-help-parsing-xml/
Share on other sites

Hey, thanks for that.

That works from one instance of <item>, but if I place more than one <item> instance into the XML, then the <article:uid> from the first <item> instance is echoed throughout the page, effectively giving:

 

 

1347132 - Headline here (Item 1)

1347132 - Second Headline (Item 2)

 

.. and I'd like each UID to relate to the <item> it's contained inside.. do you get me?

 

Thanks for your input thus far, any ideas?

WoolyG

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.