中获取XML节点的XPath可以说我有一些代码通过递归这样一个XML文件,遍历:递归函数
$xmlfile = new SimpleXMLElement('http://www.domain.com/file.xml',null,true);
xmlRecurse($xmlfile,0);
function xmlRecurse($xmlObj,$depth) {
foreach($xmlObj->children() as $child) {
echo str_repeat('-',$depth).">".$child->getName().": ".$subchild."\n";
foreach($child->attributes() as $k=>$v){
echo "Attrib".str_repeat('-',$depth).">".$k." = ".$v."\n";
}
xmlRecurse($child,$depth+1);
}
}
我将如何计算每个节点的XPath的,所以我可以将其存储映射到其他代码?
通过计算xpath,你的意思是什么? – Gordon 2010-02-22 15:57:49
我的意思是每个孩子计算其xpath - 例如/ dwml/data/location/point/@ latitude – robjmills 2010-02-22 16:01:35