RE: [PHP] simplexml and xpath

From: Date: Wed, 22 Sep 2004 16:20:27 +0000
Subject: RE: [PHP] simplexml and xpath
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-197579@lists.php.net to get a copy of this message
> So I've just recently fallen in love with simplexml. But from what I've > read, is it true that xpath doesn't really work properly? > > I'm using an XML file that has a section like this: > > <item> > <title>Title</title> > <link>Link</link> > <description>Desc</description> <dc:subject>Subject</dc:subject> > <dc:date>2004-09-20T18:15:00+00:00</dc:date> > </item> > > My sample of my PHP code is: > > <?php > $library = simplexml_load_file('file.rss'); > foreach ($library->item as $item) { > echo $item->xpath('dc:date'); > } > ?> > > I just want to get the date. Am I doing xpath incorrectly or does xpath > not > currently work properly in PHP5? > > -- > --Matthew Sims > --<http://killermookie.org> > So I figured it out. <?php $library = simplexml_load_file('file.rss'); foreach ($library->item as $item) { list( ,$date) = each($item->xpath('dc:date')); echo $date; } ?> -- --Matthew Sims --<http://killermookie.org>

« previous php.general (#197579) next »