<?php
$xYahooXML = '
<ysearchresponse responsecode="200">
<prevpage> /ysearch/web/v1/sunflower%20seeds?appid=e4j0dGfIkY0.VnPaj_m8JivWDmAdWAV50uTRuIaqvA--&format=xml&count=1&start=0 </prevpage>
<nextpage> /ysearch/web/v1/sunflower%20seeds?appid=e4j0dGfIkY0.VnPaj_m8JivWDmAdWAV50uTRuIaqvA--&format=xml&count=1&start=2 </nextpage>
<resultset_web count="1" start="1" totalhits="376055" deephits="11600000">
<result>
<abstract> Home to the <b>seed</b> brand featuring products, nutrition facts, and more. </abstract>
<clickurl> http://lrd.yahooapis.com/_ylc=X3oDMTRrYzhoc210BF9TAzIwMjMxNTI3MDIEYXBwaWQDZTRqMGRHZklrWTAuVm5QYWpfbThKaXZXRG1BZFdBVjUwdVRSdUlhcXZBLS0EcG9zAzEEc2VydmljZQNZU2VhcmNoV2ViBHNsawN0aXRsZQRzcmNwdmlkA2ZIUnh2RVBEQjJHQjIxOF9zZjhLc3dsa1RNTzJsa21qWS5FQUE2WkI-/SIG=10v00dabm/**http%3A//www.davidseeds.com/ </clickurl>
<date>2008/12/12</date>
<dispurl>www.<b>davidseeds.com</b></dispurl>
<size>7122</size>
<title>David <b>Sunflower</b> <b>Seeds</b></title>
<url>http://www.davidseeds.com/</url>
</result>
</resultset_web>
</ysearchresponse>';
$oSimpleXML = new SimpleXMLElement( $xYahooXML );
echo $oSimpleXML->resultset_web->attributes()->totalhits;
First, I used
SimpleXML as it is generally easier to parse this kind of xml with.
Second, I don't know if the DOM will complain about this, but to my knowledge for XML to be valid a node can not contain an html entity that is not in entity format aka & => & Also, besides 5 entities quot, amp, apos, lt, gt any other element has to be numerically defined.
http://en.wikipedia.org/wiki/List_of...ity_references
I had to change the &'s to & in the url's in your code to get SimpleXML to not complain about it being invalid xml etc.
Let me know if you have any additional questions.
Reputation Points: 265
Solved Threads: 126
Practically a Master Poster
Offline 624 posts
since Jul 2008