I am parsing xml file with simplexml_load_file() function. I have problem when i meet two nodes with same name. My XML file structure is:
<company>
<name>Test Co</name>
<link href="link1" rel="self"/>
<link href="link2" rel="www"/>
</company>
And here is the code:
$parametrs = simplexml_load_file("my.xml");
foreach ($parametrs->company as $param ) {
echo $param->name;
}
How can i echo link2 from each company?
This will output ‘link2’ (without quotes around it).
Also, you may want to do some checking up front that these elements exist, but I’ll leave that up to you as it’s outside the scope of the question 😉