Forum Moderators: coopster

Message Too Old, No Replies

simplexml load string parsing problems

         

kadnan

6:26 am on Dec 19, 2009 (gmt 0)

10+ Year Member



I am loading following XML(returnedby YQL)by using simplxml_load_string


<results>
<td class="titlelink2" width="75%">
<a class="offerHeading" href="http://www.site.com/product_view/id/44.htm" target="_blank">Nike Jordan Shoes</a>
</td>
<td class="titlelink2" width="75%">
<a class="offerHeading" href="http://www.site.com/product_view/id/44.htm" target="_blank">Nike Adidas Puma Timberland Hogan Prada Jordan Sports Shoes Jacket</a>
</td>
</results>

the issue is that its not parsing attributes of anchor tags and just returning the text of Anchor rather than the URL and other attributes. How should I retrieve it?

penders

1:24 pm on Dec 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Using your $XML_STRING above, the following outputs attribute values from the first anchor tag....

$xml = simplexml_load_string($XML_STRING); 
foreach($xml->td[0]->a[0]->attributes() as $name => $value) {
echo $name.' = "'.$value.'"<br>';
}

Outputs...

class = "offerHeading" 
href = "http://www.site.com/product_view/id/44.htm"
target = "_blank"

kadnan

2:10 pm on Dec 20, 2009 (gmt 0)

10+ Year Member



Thanks a bunch!