/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] simpleXML and Namespaces Help

I have a feed that has been working fine till I modified the feed to support iTunes, which uses namespaces. I am trying to get the information from the feed to display, but I am not having luck.

Here’s a snippet of the feed:

[code]
<?xml version=”1.0″?>
<rss xmlns:itunes=”http://www.itunes.com/dtds/podcast-1.0.dtd” version=”2.0″>
<channel>
<title>Company Podcasts</title>
<link>http://localhost</link>
<language>en-us</language>
<copyright>Copyright 2008</copyright>
<description><![CDATA[Description]]></description>
<itunes:subtitle>Title</itunes:subtitle>
<itunes:author>Name</itunes:author>
<itunes:summary><![CDATA[Description]]></itunes:summary>
<itunes:owner>
<itunes:name>Name</itunes:name>
<itunes:email>name@localhost</itunes:email>
</itunes:owner>
<itunes:keywords>keywords</itunes:keywords>
<itunes:image href=”http://localhost/file.jpg” />
<itunes:category text=”Government &amp; Organizations”>
<itunes:category text=”Local”/>
</itunes:category>
<itunes:category text=”Religion &amp; Spirituality”>
<itunes:category text=”Christianity”/>
</itunes:category>
<itunes:category text=”Religion &amp; Spirituality”>
<itunes:category text=”Spirituality”/>
</itunes:category>

<webMaster>webmaster@localhost</webMaster>
<lastBuildDate>Tue, 17 Jun 2008 00:35:16 GMT</lastBuildDate>
<generator>PodAdmin – The Free Web-based Podcast Management Software http://podadmin.sourceforge.net</generator>
<item>
<title>Title</title>
<itunes:author>Pastor</itunes:author>
<itunes:subtitle></itunes:subtitle>
<itunes:summary>Text: Genesis 41:1-16
Date: 06/08/08</itunes:summary>
<enclosure url=”http://localhost/file.mp3″ length=”5554304″ type=”audio/mpeg”/>
<guid>http://localhost/file.mp3</guid>
<description><![CDATA[Text: Genesis 41:1-16
Date: 06/08/08]]></description>
<pubDate>Mon, 16 Jun 2008 00:00:00 CST</pubDate>
<itunes:duration>36:59</itunes:duration>
<itunes:keywords></itunes:keywords>
</item>
<item>
<title>Dysfunction, Deception, and the Plan of God</title>
<itunes:author>Pastor</itunes:author>
<itunes:subtitle></itunes:subtitle>
<itunes:summary>Text: Genesis 27:30 – 28:9
Date: 04/13/08</itunes:summary>
<enclosure url=”http://localhost/file.mp3″ length=”7145472″ type=”audio/mpeg”/>
<guid>http://localhost/file.mp3</guid>
<description><![CDATA[Text: Genesis 27:30 – 28:9
Date: 04/13/08]]></description>
<pubDate>Sun, 11 May 2008 00:00:00 CST</pubDate>
<itunes:duration>47:35</itunes:duration>
<itunes:keywords></itunes:keywords>
</item>
</channel>
</rss>
[/code]

[code=php]
// – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
// XML Feed
function processFeed($rss,$type) {

# Initiate variables
$_GET[‘newsoutput’] = “”;
$xml = “”;

if(fopen($rss, “r”)) {
$xml = simplexml_load_file($rss);
$itunes = $xml->children(‘http://www.itunes.com/dtds/podcast-1.0.dtd’);
} else {
echo ‘<p>error msg goes here</p>’;
}

$_GET[‘newsoutput’] = “<ul class=”standard”>”;

switch ($type) {

case “sermons”:

foreach ($xml->channel->item as $item) {
for ($i = 0; $i < 50; $i++) {

foreach ($item[$i]->pubDate as $date) {
#$date = str_replace(“+0000”, “”, $date);
$date = substr($date, 0, -13);
$_GET[‘newsoutput’] .= “<li>$date<br />”;
}
foreach ($item[$i]->guid as $link) {
$_GET[‘newsoutput’] .= “<a href=”$link”><strong>”;
}
foreach ($item[$i]->title as $title) {
$_GET[‘newsoutput’] .= “$title</strong></a><br />”;
}
}
}
foreach ($itunes as $item) {
for ($i = 0; $i < 50; $i++) {

foreach ($item[$i]->author as $author) {
$_GET[‘newsoutput’] .= “$author</li>”;
}

}
}
break;
# End case “sermons”

case “home”:

foreach ($xml->channel->item as $item) {
for ($i = 0; $i < 2; $i++) {

foreach ($item[$i]->pubDate as $date) {
$date = substr($date, 0, -15);
$_GET[‘newsoutput’] .= “<li><strong>$date</strong><br />”;
}
foreach ($item[$i]->guid as $link) {
$_GET[‘newsoutput’] .= “<a href=”$link”>”;
}
foreach ($item[$i]->title as $title) {
$_GET[‘newsoutput’] .= “$title</a></li>”;
}
}
}
break;
# End case “home”

} # End Switch

$_GET[‘newsoutput’] .= “</ul>”;
echo $_GET[‘newsoutput’];
}
[/code]

and the call is:

[code=php]
<?php processFeed(“http://localhost/podcast.xml”,”sermons”); ?>
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@abovethefoldauthorJul 08.2008 — BUMP

(Please)
×

Success!

Help @abovethefold spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...