Simplexml read xml

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rcmn
Forum Newbie
Posts: 21
Joined: Tue Jul 06, 2004 10:35 am

Simplexml read xml

Post by rcmn »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I want to read "param" and the entry in it.Something like $xml->info->node->param[0]['name']. But it doesn't work like that and i was wondering if anyone know how i should do it.below the php code i'm using and the xml file to read.

Code: Select all

<?php
$string = "http://pathto/myxml.xml";

$xml = simplexml_load_file($string);

echo "host:<b>".$xml['host']."</b><br>"; /*<--this work*/
echo $xml['timestamp']."<br>";/*<--this work*/
echo "<hr>";
$xml->info->node->param[0]['name'];/*<--this DOESN"T work or any similar syntax*/

?>
XML:

Code: Select all

<node-status port="1000" host="MYHOSTNODE" timestamp="TIMEWITHHOUR">
  <info>
    <node>
      <param name="type" value="special"/>
      <param name="id" value="25486622225"/>
      <param name="version" value="0.225"/>
      <param name="up-since" value="sometime"/>
      <param name="connections" value="1"/>
      <param name="thread-count" value="5"/>
    </node>
</info>
</node-status>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
rcmn
Forum Newbie
Posts: 21
Joined: Tue Jul 06, 2004 10:35 am

Post by rcmn »

Code: Select all

foreach ($xml->info->node[0]->param as $param) {
echo  $param['name']."
";
}
Post Reply