0
您好,我有一个这样的XML代码:访问一个SimpleXML的元素导致的家长在“阵列”
<article>
<title><![CDATA[IEEE Transactions on]]></title>
<articleinfo>
<articleseqnum>13</articleseqnum>
<idamsid>0b0000648011bcfb</idamsid>
.............
我尝试用SimpleXML访问元素的父是这样的:
$xmlUrl = "example.xml"; // XML feed file/URL
$xmlStr = file_get_contents($xmlUrl);
$xmlObj = simplexml_load_string($xmlStr);
$titles = $xmlObj->xpath("//title");
foreach ($titles as $title)
{
$parent_title = $title->xpath("parent::*");
echo "Parent element of title: ". $parent_title."</br>";
}
但是我把这个结果:
Parent element of title: Array
而不是
Parent element of title: article
可能是什么问题?先谢谢你!
' - > xpath()'总是返回一个数组 - 即使它只返回一个节点。 – hakre 2012-07-15 11:46:58
嗯。好。但是,我怎么能返回所需的结果? – 2012-07-15 11:50:31
尝试使用:'name(parent :: *)'或等价的和更短的:'name(..)' – 2012-07-15 16:02:19