-- Jaggi <[email protected]> wrote (on Monday, 10 August 2009, 04:42 AM -0700): > I've been trying to use zend dom but i've been having some issues so was > wondering if someone could tell me if this was possible... > > XML: > > <channel> > ..... > <item> > <title>Flu drugs 'unhelpful' in children</title> > <description>Experts are questioning the policy of giving > antiviral drugs to children for swine flu saying it may do > more harm than good.</description> > <link> > http://news.bbc.co.uk/go/rss/-/1/hi/health/8193012.stm</link> > <guid isPermaLink="false"> > http://news.bbc.co.uk/1/hi/health/8193012.stm</guid> > <pubDate>Mon, 10 Aug 2009 10:34:55 GMT</pubDate> > <category>Health</category> > <media:thumbnail width="66" height="49" > > url="http://newsimg.bbc.co.uk/media/images/46182000/jpg/_46182934__46005163__45987312__45705292_tamiflu226i-1-1-1.jpg" > /> > </item> > <item> > <title>MI6 'is not complicit' in torture</title> > <description>The head of MI6 Sir John Scarlett tells the BBC > the British secret service has not been involved with > torture.</description> > <link> > http://news.bbc.co.uk/go/rss/-/1/hi/uk/8188307.stm</link> > <guid isPermaLink="false"> > http://news.bbc.co.uk/1/hi/uk/8188307.stm</guid> > <pubDate>Mon, 10 Aug 2009 09:41:33 GMT</pubDate> > <category>UK</category> > <media:thumbnail width="66" height="49" > > url="http://newsimg.bbc.co.uk/media/images/46181000/jpg/_46181968_raw_johnscarlett2_getty.jpg" > /> > </item> > ................ > > > This is taken off the bbc so i just grab the xml feed and then run it... > this is the PHP: > > $dom = new Zend_Dom_Query(); > $dom->setDocumentXml($xml); > $results = $dom->queryXpath( 'channel/item' ); > > this returns all the item elements which is correct. Now what i wish to do > is loop through those and run some xpath queries on that to get the > individual tags(e.g. category, title, link). Can't seem to figure this out > as if i loop through the results all i get is the string which i can't > navigate anymore.
If you're going to do XPath queries, and not CSS selector queries, I'd recommend just using straight DOM -- it provides one less layer of abstraction, and will get you all the DOM objects you'd normally expect. Zend_Dom_Query returns a Zend_Dom_Query_Result object, which proxies a DOMNodeList. If you iterate through it, you'll get individual DOMNode objects, and you can also retrieve the DOMDocument using the getDocument() method. -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/
