Re: Parsing an RSS file using expat functions

From: Date: Wed, 22 Nov 2000 21:22:38 +0000
Subject: Re: Parsing an RSS file using expat functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-26723@lists.php.net to get a copy of this message
On Wed, 22 Nov 2000, Chris Lott wrote: > I just finished going over the php builder article on parsing an XML file > and outputting HTML (good article: > http://phpbuilder.com/columns/justin20000428.php3). I think I > am grasping > the concept somewhat, but I am confused about handling duplicate tags within > different elements (that might be the wrong terminology) using PHP. > > For instance, given this as the body of an RSS file: > <channel> > <title>FoolYou News</title> > <link>http://foolyou.com/news/</link> > <description>News and Notes from around the web...</description> > <language>en-us</language> > > <item> > <title>Henderson Reports</title> > <link>http://www.foo.org/henderson/</link> > <description>Many interesting reports by John > Henderson!</description> > </item> > > I want the description of a channel to be rendered quite differently than > the description of an item, but since they have the same name this doesn't > seem possible? One method is to maintain a 'stack' of the elements in an array. This way your start/end element handlers can know what kind of element their parent (If there is one) is. A good tutorial that provides an example of this is at http://www.zend.com/zend/art/parsing.php Specifically, I recommend reading through the section on Representing the Document Structure, which explains the process. Matt

« previous php.general (#26723) next »