...

View Full Version : simplexml_load_string begginers question



umen242
02-10-2009, 10:52 PM
Hello all
im using simplexml_load_string to convert xml string to object
and then i go to each node by name following the node hierarchy for example
if i have xml like to get c i just do

$xml = simplexml_load_string($req);
print ($xml->a->b->c);


<a>
<b>
<c>
</c>
</b>
</a>
but how can i get for example second or third <c> if i have something like this :

<a>
<b>
<c>
</c>
<c>
</c>
<c>
</c>
</b>
</a>
still using the xml object converted from simplexml_load_string
Thanks

kbluhm
02-10-2009, 11:11 PM
<a> ... </a> will be the name, so you'll be starting with <b> ... </b>:


$xml = simplexml_load_string( $req );
foreach ( $xml->b->c as $c )
{
echo $c, "\n";
}

umen242
02-11-2009, 07:08 AM
Thanks for the response
is there any method to avoid looping , maybe by index ( [0],[1],[2] ...)
im not restrict to simplexml_load_string i can use other method also
Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum