Generating Podcast RSS using PHP5 Dom
Posted: Wed Mar 12, 2008 2:59 pm
Hi All,
This is my first time in a long time posting on the forum. I think this forum is great.
I'm currently working on a RSS/Podcast generating library using php5's dom library. I'm running into a little problem with xml namespace.
First, I'm not generating the correct namespace string. Below is my code setting the namespace for itunes podcast.
The above code generated this:
While I want it like this:
I'm also having trouble with Xpath to search for nodes. Below is my getElements function
Here is an example query and xml:
I have been reading all the dom documentations, but they are not that helpful with no examples on usage.
Any one can give me a bit of advise is appreciated. I have been trying to solve this problem for the past 2 days.
Thanks
Guang
This is my first time in a long time posting on the forum. I think this forum is great.
I'm currently working on a RSS/Podcast generating library using php5's dom library. I'm running into a little problem with xml namespace.
First, I'm not generating the correct namespace string. Below is my code setting the namespace for itunes podcast.
Code: Select all
$qualifiedName = 'itunes';
$namespaceURI = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
public function setXmlNameSpace($namespaceURI, $qualifiedName)
{
$this->nameSpaceURI = $namespaceURI;
$this->qualifiedName = $qualifiedName;
$attrNS = $this->getXMLDocument()->createAttributeNS($namespaceURI, $qualifiedName);
$this->getRootElement()->appendChild($attrNS);
}
Code: Select all
<rss xmlns="http://www.itunes.com/dtds/podcast-1.0.dtd" itunes="" version="2.0">
Code: Select all
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
Code: Select all
public function getElements($xpathQuery)
{
$xpath = new DOMXPath($this->getXMLDocument());
$xpath->registerNamespace($this->qualifiedName, $this->nameSpaceURI);
$domNodeList = $xpath->query($xpathQuery, $this->getXMLDocument());
if($domNodeList->length > 0)
{
return $domNodeList;
}
return false;
}
Code: Select all
qualifiedName: itunes
nameSpaceURI: http://www.itunes.com/dtds/podcast-1.0.dtd
xpathQuery: itunes:title
domNodeList->length: 0
XML:
<?xml version="1.0" encoding="utf-8"?>
<channel xmlns="http://www.itunes.com/dtds/podcast-1.0.dtd" itunes="">
<title>Podcasts Feed</title>
<link>http://www.localhost.local/podcasts.htm</link>
<language>en-us</language>
<copyright>©2008 xxxx.</copyright>
<itunes:author>localhost</itunes:author>
<itunes:name>John Doe</itunes:name>
<itunes:email>localhost@localhost.com</itunes:email>
<itunes:image href="http://www.localhost.local/images/site/logo.jpg" />
</channel>
Any one can give me a bit of advise is appreciated. I have been trying to solve this problem for the past 2 days.
Thanks
Guang