$node = $root - >f i r s tCh i ld ;
$ i = 0;
/ /Now keep l oop ing th rough as l ong as the re i s a node to work
/ /w i th . (A t the bot tom o f the l oop , the code moves to the next
/ / s ib l i ng , so when i t runs out o f s ib l i ngs , the rou t ine s tops .
whi le ($node) {
/ / Fo r each node , check to see whether i t ' s a Resu l t e lement or
/ / one o f the i n fo rmat iona l e lements at the s ta r t o f the document .
sw i t ch ($node->nodeName) {
/ /Resu l t e lements need more ana lys i s .
case ' Resu l t ' :
/ /Add each ch i ld node o f the Resu l t to the resu l t ob jec t ,
/ / aga in s ta r t ing wi th the f i r s t ch i ld .
$subnode = $node ->f i r s tCh i ld ;
whi le ($subnode) {
/ /Some o f these nodes j us t are j u s t whi tespace , which does
/ /no t have ch i ld ren .
i f ($subnode ->hasCh i ldNodes ( ) ){
/ / I f i t does have ch i ld ren , get a NodeL i s t o f them, and
/ / l oop th rough i t .
$subnodes = $subnode ->ch i ldNodes ;
fo reach($subnodes as $n) {
/ /Aga in check fo r ch i ld ren , add ing them d i rec t l y or
/ / i nd i rec t l y as appropr ia te .
i f ($n - >hasCh i ldNodes ( ) ) {