Get content from xml file

by mariganesh 2012-12-28 10:27:57

If you want get data from xml file.use this following code and get the specific data

For Example

Filename : simple.xml


<ALEXA VER="0.9" URL="hscripts.com/" HOME="0" AID="=">
<SD TITLE="A" FLAGS="DMOZ" HOST="hscripts.com">
<TITLE TEXT="HIOX Free Scripts"/>
<CREATED DATE="06-Oct-2004" DAY=" 6" MONTH="10" YEAR="2004"/>
<EMAIL ADDR="support@hioxindia.com"/>
<LANG LEX="en" CODE="us-ascii"/>
<LINKSIN NUM="1296"/>
<SPEED TEXT="2325" PCT="28"/>
<REVIEWS AVG="4.0" NUM="1"/>
<CHILD SRATING="0"/>
</SD>

<DMOZ>
<SITE BASE="hscripts.com/" TITLE="HIOX Free Scripts" DESC="Free PHP scripts including: Mail/Support Interface, Guest Book, Calendars, Rating System, Image Rotator, DB Query Tool, counters, Visitor Tracking, Calculator, Broken Link Analyser.">
<CATS><CAT ID="Top/Computers/Programming/Languages/PHP/Scripts" TITLE="PHP/Scripts" CID="377810"/></CATS>
</SITE>
</DMOZ>

<SD>
<POPULARITY URL="hscripts.com/" TEXT="15436" SOURCE="panel"/>
<REACH RANK="12369"/>
<RANK DELTA="-3638"/>
<COUNTRY CODE="IN" NAME="India" RANK="4913"/>
</SD>
</ALEXA>



Here It is xml code Then I want to get specific alexa rank from this code .

"POPULARITY URL="hscripts.com/" TEXT="15436" SOURCE="panel"/"

Here hscripts.com alexa rank is 15436


$xml = simplexml_load_file("simple.xml");
foreach($xml->children() as $child)
{
//Now you get childnodes of xml file (Alexa , SD , Dmoz ,SD)
if($child->getName()=="SD")
{
foreach($child->children() as $child1) //Get the SD childnodes Names (popularity,REACh,RANK,COUNTRY)
{
if($child1->getName()=="POPULARITY")
{
$child2=$child1->attributes(); //Get the POPULARITY attributes (hscripts.com,15436 ,panel)

$arank=$child2[1];

}

}

}

}
echo $arank //Now you get alexa rank of the hscripts site



1235
like
0
dislike
0
mail
flag

You must LOGIN to add comments