Jump to content

PHP Parsing XML with Attributes using Kevin Yank PHP Parsing Method


kbrice

Recommended Posts

I'm using Kevin Yank PHP Parsing Method from http://www.sitepoint.com/article/php-xml-parsing-rss-1-0/4/. But using my xml file below I can't seem to retrieve the URL from the link tag. Can anyone help?

Part of my php code:

function startElement($parser, $tagName, $attrs) {
       if ($this->insideitem) {
           $this->tag = $tagName;
           $this->attr = $attrs;
       } elseif ($tagName == "ITEM") {
           $this->insideitem = true;
       }
   }

   function endElement($parser, $tagName) {
       if ($tagName == "ITEM") {
           printf("<p><b><a href='%s'>%s</a></b></p>",
             trim($attrs['link']),htmlspecialchars(trim($this->title)));
           printf("<p>%s</p>",
             htmlspecialchars(trim($this->description)));
           $this->title = "";
           $this->updated = "";
           $this->description = "";
           $this->link = "";
           $this->insideitem = false;
       }
   } 

 

Example of my XML file from an atom RSS Feed:

 

<item>
    <title type="html">...</title>
    <link rel="alternate" type="text/html" href="http://www.mydomain.com/nyc-technology/" />
    <description>...</description>
    <updated>...</updated>
</item>

 

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.