how to parse this xml data using php? -
how to parse this xml data using php? -
<?xml version="1.0" encoding="utf-8"?> <alexa ver="0.9" url="infosys.com/" home="0" aid="="> <rls prefix="http://" more="62"> <rl href="wipro.com/" title="wipro corporation"/> <rl href="tcs.com/" title="tata consultancy services"/> <rl href="satyam.com/" title="satyam computer services ltd"/> <rl href="ibm.com/" title="ibm corporation"/> <rl href="rediff.com/" title="rediff.com republic of india ltd."/> <rl href="moneycontrol.com/" title="moneycontrol.com"/> <rl href="in.com/" title="in.com"/> <rl href="google.co.in/" title="google india"/> <rl href="www.stiknowledge.com/" title="business process outsourcing | help desk outsourcing , certification"/> <rl href="www.sourcinginterests.org/" title="sourcing interests group"/> <rl href="www.dice.com/" title="www.dice.com/"/> </rls> <sd title="a" flags="dmoz" host="infosys.com"> <title text="infosys"/> <addr street=" 44, electronics city, hosur road" city=" bangalore, karnataka 560 100" state="" zip="" country=" india" /> <created date="17-jul-1992" day="17" month="07" year="1992"/> <phone number="91 80 852 0261"/> <owner name="infosys technologies limited"/> <email addr="marketing@infosys.com"/> <lang lex="en" code="us-ascii"/> <linksin num="2858"/> <speed text="1308" pct="55"/> <reviews avg="5.0" num="1"/> <child srating="0"/> </sd> <keywords> <keyword val="karnataka"/> <keyword val="bangalore"/> </keywords><dmoz> <site base="infosys.com/" title="infosys" desc="infosys (nasdaq:infy) defines, designs , delivers enabled business solutions. these provide strategic differentiation , operational superiority, thereby increasing competitiveness. each solution delivered industry-benchmark infosys predictability gives peace of mind."> <cats> <cat id="top/computers/software/consultants" title="software/consultants" cid="379688"/> <cat id="top/regional/asia/india/karnataka/localities/bangalore/business_and_economy/computers_and_internet/software" title="computers , internet/software" cid="497626"/> </cats> </site> </dmoz> <sd> <popularity url="infosys.com/" text="15422"/> <reach rank="17335"/> <rank delta="+1"/> </sd> </alexa>
i have used $xml= new simplexmlelement('xml info here') used $x=$xml->xpath('/alexa); getting how access linksin num , reach rank here. if send $x in foreach foreach($x $y){ $y->linksin num; } throw error since there gap between linksin , num
this should work:
$xml = simplexml_load_string($datahere); $rank = (int)$xml->sd->reach['rank']; documentation: http://nl3.php.net/simplexml_load_string
if have url xml:
$xml = simplexml_load_file($url_to_file); php xml
Comments
Post a Comment