I have an xml file like this:
<js>
<ba>
<ea>
<jd>
<option>first sko</option>
<option>second sko</option>
<option>third sko</option>
<option>fourth sko</option>
<option>fifth sko</option>
</jd>
</ea>
</ba>
</js>
I want to retrieve the tag name of the grandparent tag (i.e. "ea") starting from each value of the "option" tag.
So to get two levels up from this tag I have tried:
$xmlItem = simplexml_load_file(thexmlfile.xml);
foreach ($xmlItem->xpath('//jd/option') as $juzg) {
$cid = $xmlItem->xpath("name(//*[*[option = '" . $juzg . "']])");
$item['cid'] = (string)$cid;
}
The result I get when I echo the $cid or the $item['cid'] is an "Array" for each loop.
I am looking for the full script that will go in place of:
$cid = $xmlItem->xpath("name(//*[*[option = '" . $juzg . "']])");
I will appreciate any guidance on this issue.