Hi There,

I have an XML data

<coordinators branch="xx"><coordinator cnum="xx">
<value key="role" type="string">BC</value>
<value key="role_desc" type="string">role</value>
<value key="name" type="string">xx</value>
<value key="tel_number" type="string"/>
<value key="email_address" type="string">xx</value>
</coordinator>
<coordinator cnum="xx">
<value key="role" type="string">BC</value>
<value key="role_desc" type="string">role</value>
<value key="name" type="string">xx</value>
<value key="tel_number" type="string"/>
<value key="email_address" type="string">xx</value>
</coordinator>
</coordinators>

I need to get name and email address from this like $names $emails ...

Any one have an idea?

Thanks

Thx for that.

Any coding example maybe?

I did search online but couldnt sort it out..

See example #5 in the documentation I linked.

Hi,

This maybe the simplest example I could ever think of.. Say, your above xml file is called test.xml, then you can easily parse the email XX and the name: XX from it by using these few lines of php codes.

<?php
## type in your xml file location
$xml ='test.xml';
## remove @ to debug
$xml = @simplexml_load_file($xml); 
 foreach($xml as $items)
{
echo "Name: ".$items->value[2]." Email: ".$items->value[4]."<br/>";

}

  ?>

We can also assign them into variables as you wish, as shown in my example below..

$name = $items->value[2];
$email = $items->value[4];


You may want to consider setting up some check points to see if the xml file does exist, like so

if (file_exists('test.xml')) {
$xml = @simplexml_load_file($xml);

}
## instruct the script what to do if xml file does not exist.

else{

## it's your call here

}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.