MyBB Community Forums

Full Version: XML parsing question.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alexa site info returns the following XML.

<ALEXA VER="0.9" URL="mybb.com/" HOME="0" AID="=">
<RLS PREFIX="http://" more="0">
</RLS>
<SD TITLE="A" FLAGS="DMOZ" HOST="mybb.com">
<TITLE TEXT="mybb.com | Travel "/>
<LINKSIN NUM="20581"/>
<SPEED TEXT="1265" PCT="56"/>
<REVIEWS AVG="4.0" NUM="4"/>
<CHILD SRATING="0"/>
</SD>
<DMOZ>
<SITE BASE="mybb.com/" TITLE="MyBB" DESC="The official site for the forum software informs on features, ideas, and mods, and offers downloads and a forum.">
<CATS><CAT ID="Top/Computers/Programming/Languages/PHP/Scripts/Forums/MyBB" TITLE="Forums/MyBB" CID="377847"/></CATS>
</SITE>
</DMOZ>
<SD>
<POPULARITY URL="mybb.com/" TEXT="5977"/>
<REACH RANK="8781"/>
<RANK DELTA="-107"/>
</SD>
</ALEXA>

I'm using simplexml to parse the data.
In the XML returned, it has 2 elements named <SD>. I wish to get the POPULARITY data from second <SD> element, but since there is already an SD element present, it doesn't read the second one.

For example, i can read LINSKIN data from first <SD> family with $xml->SD->LINKSIN['NUM']

But i can't access POPULARITY data from second <SD> family using $xml->SD->POPULARITY['TEXT'].

Is there any way to get it?
~ Looking it over.. the XML isn't consistent at all.

Looping may help the issue.
(2012-02-29, 06:51 AM)2$CoMpLiCaTeD$4u Wrote: [ -> ]~ Looking it over.. the XML isn't consistent at all.

Looping may help the issue.

Thanks 2$CoMpLiCaTeD$4u. Smile
Figured it out already. Just needed to supply $xml->SD to loop and concatenate the popularity (text) values. Smile