I am hoping someone can help me with this.
I am fairly new to XML parsing so XML parsing and I have only dealt with fairly simple parsing so far.
I am currently stuck with the following problem...
I have XML with this structure: -
<members>
<member>
<name>David Smith</name>
<information>
<description>home telephone</description>
<given_information>
<details>0123465987</details>
</given_information>
</information>
<information>
<description>mobile telephone</description>
<given_information>
<details>056142856987</details>
</given_information>
</information>
<information>
<description>email address</description>
<given_information>
<details>d.smith@yahoo.com</details>
</given_information>
</information>
</member>
</members>
I am using simplexml & xpath like this: -
$XML_load = simplexml_load_file('members.xml');
foreach ($XML_load->members->xpath('//member') as $member)
{
$member_name = $member->name;
}
The problem I have is that I dont know how to get a variable from the element based on the element. So I need to be able to create the variables $mobile_number, $home_number and $email_address accurately based on the information in the ancestor element of .
Can anyone help me with this? Any advice would be greatly appreciated.
I hope I have explained the problem well enough and my terminology is correct but please forgive me if it is not as I am still a newbie at this.
BTW is using simplexml/xpath like this the best way to do it? I have heard xmlDOM is better but I cant seem to find any resources related to that which would help me with the problem above.
Thanks in advance!
Try this for a start: