$xmlItem->xpath
returns an Array, so if you do (string)$xmlItem->xpath()
you will always get 'Array'
In your example you would have to iterate again over $cid or just select $cid[0], but I don't think getting the name of the parent like this will work.
Either do:
foreach ($xmlItem->xpath('//jd/option') as $juzg) {
$cid = $xmlItem->xpath("//*[*[option = '".$juzg."']]");
$item['cid'] = $cid[0]->getName();
}
However this only works if there isn't any other option element in your xml document with the same content, so rather than relying on the content of the element just select its parent nodes:
foreach ($xmlItem->xpath('//jd/option') as $juzg) {
$cid = $juzg->xpath('../..');
$item['cid'] = $cid[0]->getName();
}
Here you even can be sure that $cid
will only have one object because you select a parent and an element will always have just one parent.