<?xml version="1.0"?>
<?xml-stylesheet
href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"
?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel rdf:about="http://pear.php.net/bugs/search.php">
    <title>PEAR Bug Search Results</title>
    <link>http://pear.php.net/bugs/search.php?cmd=display&amp;package_name%5B0%5D=XML_Feed_Parser</link>
    <description>Search Results</description>
    <dc:language>en-us</dc:language>
    <dc:creator>pear-webmaster@lists.php.net</dc:creator>
    <dc:publisher>pear-webmaster@lists.php.net</dc:publisher>
    <admin:generatorAgent rdf:resource="http://pear.php.net/bugs"/>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>
    <items>
     <rdf:Seq>
      <rdf:li rdf:resource="http://pear.php.net/bug/16416" />
      <rdf:li rdf:resource="http://pear.php.net/bug/15366" />
      <rdf:li rdf:resource="http://pear.php.net/bug/12916" />
      <rdf:li rdf:resource="http://pear.php.net/bug/10335" />

     </rdf:Seq>
    </items>
  </channel>

  <image rdf:about="http://pear.php.net/gifs/pearsmall.gif">
    <title>PEAR Bugs</title>
    <url>http://pear.php.net/gifs/pearsmall.gif</url>
    <link>http://pear.php.net/bugs</link>
  </image>

    <item rdf:about="http://pear.php.net/bug/16416">
      <title>XML_Feed_Parser: Bug 16416 [Open] atom:link causes getLink to fail for RSS2.php</title>
      <link>http://pear.php.net/bugs/16416</link>
      <content:encoded><![CDATA[<pre>XML_Feed_Parser Bug
Reported by crimson
2009-07-09T04:59:12+00:00
PHP: 5.2.5 OS: Debian Lenny Package Version: 1.0.3

Description:
------------
The RSS 2.0 spec specifies that you should use &lt;link&gt; however some sites such as http://workbench.cadenhead.org/news/3284/adding-atomlink-your-rss-feed recommend adding &lt;atom:link /&gt; also.

getElementsByTagName will return both these links when searching for 'link'. If the atom:link is first then $link-&gt;nodeValue is an empty string and this eventually calls combineBases passing $element-&gt;baseURI (which in my case ends up being the folder of the file)

An example of the kind of feed that can trigger this is  http://blog.mudrak.name/feed/?tag=mahara

I have attached a diff of my change to fix this issue using xpath to only match &lt;link&gt; and not &lt;atom:link&gt; (or any other namespaced link attributes).

Actual result:
--------------
ben@tifa:Parser/$ git diff
diff --git a/htdocs/lib/pear/XML/Feed/Parser/RSS2.php b/htdocs/lib/pear/XML/Feed/Parser/RSS2.php
index c5d79d1..308a4ab 100644
--- a/htdocs/lib/pear/XML/Feed/Parser/RSS2.php
+++ b/htdocs/lib/pear/XML/Feed/Parser/RSS2.php
@@ -321,7 +321,8 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
      */
     function getLink($offset, $attribute = 'href', $params = array())
     {
-        $links = $this-&gt;model-&gt;getElementsByTagName('link');
+        $xPath = new DOMXPath($this-&gt;model);
+        $links = $xPath-&gt;query('//link');
 
         if ($links-&gt;length &lt;= $offset) {
             return false;
@@ -331,4 +332,4 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
     }
 }
 
-?&gt;
\ No newline at end of file
+?&gt;</pre>]]></content:encoded>
      <description><![CDATA[<pre>XML_Feed_Parser Bug
Reported by crimson
2009-07-09T04:59:12+00:00
PHP: 5.2.5 OS: Debian Lenny Package Version: 1.0.3

Description:
------------
The RSS 2.0 spec specifies that you should use &lt;link&gt; however some sites such as http://workbench.cadenhead.org/news/3284/adding-atomlink-your-rss-feed recommend adding &lt;atom:link /&gt; also.

getElementsByTagName will return both these links when searching for 'link'. If the atom:link is first then $link-&gt;nodeValue is an empty string and this eventually calls combineBases passing $element-&gt;baseURI (which in my case ends up being the folder of the file)

An example of the kind of feed that can trigger this is  http://blog.mudrak.name/feed/?tag=mahara

I have attached a diff of my change to fix this issue using xpath to only match &lt;link&gt; and not &lt;atom:link&gt; (or any other namespaced link attributes).

Actual result:
--------------
ben@tifa:Parser/$ git diff
diff --git a/htdocs/lib/pear/XML/Feed/Parser/RSS2.php b/htdocs/lib/pear/XML/Feed/Parser/RSS2.php
index c5d79d1..308a4ab 100644
--- a/htdocs/lib/pear/XML/Feed/Parser/RSS2.php
+++ b/htdocs/lib/pear/XML/Feed/Parser/RSS2.php
@@ -321,7 +321,8 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
      */
     function getLink($offset, $attribute = 'href', $params = array())
     {
-        $links = $this-&gt;model-&gt;getElementsByTagName('link');
+        $xPath = new DOMXPath($this-&gt;model);
+        $links = $xPath-&gt;query('//link');
 
         if ($links-&gt;length &lt;= $offset) {
             return false;
@@ -331,4 +332,4 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type
     }
 }
 
-?&gt;
\ No newline at end of file
+?&gt;</pre>]]></description>
      <dc:date>2009-07-09T04:59:12+00:00</dc:date>
      <dc:creator>ben &amp;#x61;&amp;#116; crimson &amp;#x64;&amp;#111;&amp;#x74; net &amp;#x64;&amp;#111;&amp;#x74; nz</dc:creator>
      <dc:subject>XML_Feed_Parser Bug</dc:subject>
    </item>
    <item rdf:about="http://pear.php.net/bug/15366">
      <title>XML_Feed_Parser: Bug 15366 [Analyzed] Schema validation doesn't work - libxml problem</title>
      <link>http://pear.php.net/bugs/15366</link>
      <content:encoded><![CDATA[<pre>XML_Feed_Parser Bug
Reported by doconnor
2008-12-20T21:12:10+00:00
PHP: 5.2.6 OS:  Package Version: CVS

Description:
------------
This is:
http://bugzilla.gnome.org/show_activity.cgi?id=565219

for validating against atom.rng</pre>]]></content:encoded>
      <description><![CDATA[<pre>XML_Feed_Parser Bug
Reported by doconnor
2008-12-20T21:12:10+00:00
PHP: 5.2.6 OS:  Package Version: CVS

Description:
------------
This is:
http://bugzilla.gnome.org/show_activity.cgi?id=565219

for validating against atom.rng</pre>]]></description>
      <dc:date>2008-12-21T00:12:44+00:00</dc:date>
      <dc:creator>daniel &amp;#x64;&amp;#111;&amp;#x74; oconnor &amp;#x61;&amp;#116; gmail &amp;#x64;&amp;#111;&amp;#x74; com</dc:creator>
      <dc:subject>XML_Feed_Parser Bug</dc:subject>
    </item>
    <item rdf:about="http://pear.php.net/bug/12916">
      <title>XML_Feed_Parser: Bug 12916 [Analyzed] German umlauts are displayed wrong</title>
      <link>http://pear.php.net/bugs/12916</link>
      <content:encoded><![CDATA[<pre>XML_Feed_Parser Bug
Reported by sunfish
2008-01-16T15:19:56+00:00
PHP: 5.2.3 OS:  Package Version: 1.0.2

Description:
------------
German umlauts (ÃÃÃÃ¤Ã¶Ã¼Ã) from an atom xml file (encoding=&quot;iso-8859-1&quot;) are displayed wrong after parsing, eg. http://www.keine-gentechnik.de/news-regionen.xml





Test script:
---------------
This solution works for me

Type.php, Line 352
    // remove htmlentities, because they  prevent utf8_decode conversion
[$content .= htmlentities($node-&gt;nodeValue);]
$content .= $node-&gt;nodeValue;

Atom.php, line 263
   // add utf8_decode
[return $content-&gt;nodeValue;]
return utf8_decode($content-&gt;nodeValue);</pre>]]></content:encoded>
      <description><![CDATA[<pre>XML_Feed_Parser Bug
Reported by sunfish
2008-01-16T15:19:56+00:00
PHP: 5.2.3 OS:  Package Version: 1.0.2

Description:
------------
German umlauts (ÃÃÃÃ¤Ã¶Ã¼Ã) from an atom xml file (encoding=&quot;iso-8859-1&quot;) are displayed wrong after parsing, eg. http://www.keine-gentechnik.de/news-regionen.xml





Test script:
---------------
This solution works for me

Type.php, Line 352
    // remove htmlentities, because they  prevent utf8_decode conversion
[$content .= htmlentities($node-&gt;nodeValue);]
$content .= $node-&gt;nodeValue;

Atom.php, line 263
   // add utf8_decode
[return $content-&gt;nodeValue;]
return utf8_decode($content-&gt;nodeValue);</pre>]]></description>
      <dc:date>2009-05-23T18:59:34+00:00</dc:date>
      <dc:creator>ulrich-fischer &amp;#x61;&amp;#116; gmx &amp;#x64;&amp;#111;&amp;#x74; net</dc:creator>
      <dc:subject>XML_Feed_Parser Bug</dc:subject>
    </item>
    <item rdf:about="http://pear.php.net/bug/10335">
      <title>XML_Feed_Parser: Feature/Change Request 10335 [Assigned] Can XML_Feed_Parser get nodeValue within the namespace?</title>
      <link>http://pear.php.net/bugs/10335</link>
      <content:encoded><![CDATA[<pre>XML_Feed_Parser Feature/Change Request
Reported by ezka1209a
2007-03-12T02:13:07+00:00
PHP: 5.1.6 OS: FreeBSD6.1 Package Version: 1.0.1

Description:
------------
Now I'm trying to get nodeValue within a certain namespace.But currently,this package doesn't support this feature.Do you have any plan to support namespaces?

For example,here is the xml file.and I want to get element like this,&quot;$element-&gt;{ex:rank}&quot;.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;rss version=&quot;2.0&quot; xmlns:ex=&quot;http://www.example.com/xml/xmlns# &quot;&gt;
 &lt;channel&gt;
  &lt;title&gt;Sample&lt;/title&gt;
  &lt;link&gt;http://www.example.com/&lt;/link&gt;
  &lt;description&gt;This is sample xml file.&lt;/description&gt;
&lt;item&gt;
  &lt;title&gt;Foo&lt;/title&gt;
  &lt;link&gt;http://www.example.com/bar.html&lt;/link&gt;
  &lt;ex:rank&gt;1&lt;/ex:rank&gt;
&lt;/item&gt;
(snip)...
&lt;/channel&gt;
&lt;/rss&gt;

Now I get like this:
$namespace = 'http://www.example.com/xml/xmlns#';
$feed = new XML_Feed_Parser($xml_source);
foreach ($feed as $entry) {
  echo $ranks = $entry-&gt;model-&gt;getElementsByTagNameNS($namespace, 'rank')-&gt;item(0)-&gt;nodeValue;
}

But this way is too long for me.And `echo $e-&gt;{ex:rank};' would be intuitively.I wrote the patch to support this notation.Can others agree with my idea?If you have better idea,I want to know.

== patch ==
diff -u Parser.org/RSS2.php Parser/RSS2.php
--- Parser.org/RSS2.php	Fri Mar  2 14:47:40 2007
+++ Parser/RSS2.php	Fri Mar  2 14:47:57 2007
@@ -101,7 +101,7 @@
         'date' =&gt; array('pubDate'),
         'author' =&gt; array('managingEditor'));
 
-    protected $namespaces = array(
+    public $namespaces = array(
         'dc' =&gt; 'http://purl.org/rss/1.0/modules/dc/',
         'content' =&gt; 'http://purl.org/rss/1.0/modules/content/'
         
diff -u Parser.org/Type.php Parser/Type.php
--- Parser.org/Type.php	Wed Feb 28 14:09:01 2007
+++ Parser/Type.php	Fri Mar  2 15:03:51 2007
@@ -84,6 +84,10 @@
                 }
             }
         }
+        if( strstr($call,&quot;:&quot;) ){
+            list($ns_prefix,$method) = explode(&quot;:&quot;,$call);
+            return $this-&gt;getTextNS($ns_prefix,$method,$arguments);
+        }
 
         if (empty($this-&gt;map[$call])) {
             return false;
@@ -241,6 +245,17 @@
         }
         return false;
     }
+    protected function getTextNS($ns_prefix,$method, $arguments = array())
+    {
+        $namespace = $this-&gt;parent-&gt;namespaces[$ns_prefix];
+
+        $tags = $this-&gt;model-&gt;getElementsByTagNameNS($namespace,$method);
+        if ($tags-&gt;length &gt; 0) {
+            $value = $tags-&gt;item(0)-&gt;nodeValue;
+            return $value;
+        }
+        return false;
+    }
 
     /**
      * Apply various rules to retrieve category data.
--- Parser.php.org	Fri Mar  2 15:00:32 2007
+++ Parser.php	Fri Mar  2 15:02:18 2007
@@ -181,6 +181,14 @@
 
         /* Instantiate feed object */
         $this-&gt;feed = new $class($this-&gt;model, $strict);
+        /* Find third party's namespaces */
+        if( preg_match_all(&quot;|xmlns:(.+)=['\&quot;]([^&gt;]+)['\&quot;]|i&quot;,$feed,$matches) ){
+            foreach( $matches[1] as $key=&gt;$prefix ){
+                if( empty($this-&gt;feed-&gt;namespaces[$prefix]) ){
+                    $this-&gt;feed-&gt;namespaces[$prefix] = $matches[2][$key];
+                }
+            }
+        }
     }
 
     /**


Test script:
---------------
$namespace = 'http://www.example.com/xml/xmlns#';
$feed = new XML_Feed_Parser($xml_source);
foreach ($feed as $entry) {
  echo $entry-&gt;{&quot;ex:rank&quot;}; 
}

Expected result:
----------------
1

Actual result:
--------------
cannot get any value.</pre>]]></content:encoded>
      <description><![CDATA[<pre>XML_Feed_Parser Feature/Change Request
Reported by ezka1209a
2007-03-12T02:13:07+00:00
PHP: 5.1.6 OS: FreeBSD6.1 Package Version: 1.0.1

Description:
------------
Now I'm trying to get nodeValue within a certain namespace.But currently,this package doesn't support this feature.Do you have any plan to support namespaces?

For example,here is the xml file.and I want to get element like this,&quot;$element-&gt;{ex:rank}&quot;.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;rss version=&quot;2.0&quot; xmlns:ex=&quot;http://www.example.com/xml/xmlns# &quot;&gt;
 &lt;channel&gt;
  &lt;title&gt;Sample&lt;/title&gt;
  &lt;link&gt;http://www.example.com/&lt;/link&gt;
  &lt;description&gt;This is sample xml file.&lt;/description&gt;
&lt;item&gt;
  &lt;title&gt;Foo&lt;/title&gt;
  &lt;link&gt;http://www.example.com/bar.html&lt;/link&gt;
  &lt;ex:rank&gt;1&lt;/ex:rank&gt;
&lt;/item&gt;
(snip)...
&lt;/channel&gt;
&lt;/rss&gt;

Now I get like this:
$namespace = 'http://www.example.com/xml/xmlns#';
$feed = new XML_Feed_Parser($xml_source);
foreach ($feed as $entry) {
  echo $ranks = $entry-&gt;model-&gt;getElementsByTagNameNS($namespace, 'rank')-&gt;item(0)-&gt;nodeValue;
}

But this way is too long for me.And `echo $e-&gt;{ex:rank};' would be intuitively.I wrote the patch to support this notation.Can others agree with my idea?If you have better idea,I want to know.

== patch ==
diff -u Parser.org/RSS2.php Parser/RSS2.php
--- Parser.org/RSS2.php	Fri Mar  2 14:47:40 2007
+++ Parser/RSS2.php	Fri Mar  2 14:47:57 2007
@@ -101,7 +101,7 @@
         'date' =&gt; array('pubDate'),
         'author' =&gt; array('managingEditor'));
 
-    protected $namespaces = array(
+    public $namespaces = array(
         'dc' =&gt; 'http://purl.org/rss/1.0/modules/dc/',
         'content' =&gt; 'http://purl.org/rss/1.0/modules/content/'
         
diff -u Parser.org/Type.php Parser/Type.php
--- Parser.org/Type.php	Wed Feb 28 14:09:01 2007
+++ Parser/Type.php	Fri Mar  2 15:03:51 2007
@@ -84,6 +84,10 @@
                 }
             }
         }
+        if( strstr($call,&quot;:&quot;) ){
+            list($ns_prefix,$method) = explode(&quot;:&quot;,$call);
+            return $this-&gt;getTextNS($ns_prefix,$method,$arguments);
+        }
 
         if (empty($this-&gt;map[$call])) {
             return false;
@@ -241,6 +245,17 @@
         }
         return false;
     }
+    protected function getTextNS($ns_prefix,$method, $arguments = array())
+    {
+        $namespace = $this-&gt;parent-&gt;namespaces[$ns_prefix];
+
+        $tags = $this-&gt;model-&gt;getElementsByTagNameNS($namespace,$method);
+        if ($tags-&gt;length &gt; 0) {
+            $value = $tags-&gt;item(0)-&gt;nodeValue;
+            return $value;
+        }
+        return false;
+    }
 
     /**
      * Apply various rules to retrieve category data.
--- Parser.php.org	Fri Mar  2 15:00:32 2007
+++ Parser.php	Fri Mar  2 15:02:18 2007
@@ -181,6 +181,14 @@
 
         /* Instantiate feed object */
         $this-&gt;feed = new $class($this-&gt;model, $strict);
+        /* Find third party's namespaces */
+        if( preg_match_all(&quot;|xmlns:(.+)=['\&quot;]([^&gt;]+)['\&quot;]|i&quot;,$feed,$matches) ){
+            foreach( $matches[1] as $key=&gt;$prefix ){
+                if( empty($this-&gt;feed-&gt;namespaces[$prefix]) ){
+                    $this-&gt;feed-&gt;namespaces[$prefix] = $matches[2][$key];
+                }
+            }
+        }
     }
 
     /**


Test script:
---------------
$namespace = 'http://www.example.com/xml/xmlns#';
$feed = new XML_Feed_Parser($xml_source);
foreach ($feed as $entry) {
  echo $entry-&gt;{&quot;ex:rank&quot;}; 
}

Expected result:
----------------
1

Actual result:
--------------
cannot get any value.</pre>]]></description>
      <dc:date>2007-11-06T09:44:35+00:00</dc:date>
      <dc:creator>ezka1209 &amp;#x61;&amp;#116; gmail &amp;#x64;&amp;#111;&amp;#x74; com</dc:creator>
      <dc:subject>XML_Feed_Parser Feature/Change Request</dc:subject>
    </item>
</rdf:RDF>
