PHP Xpath不';t return“;“生活”;节点列表
有时,似乎返回的域名列表不是活的 当使用类似子节点的访问时,它是活动的PHP Xpath不';t return“;“生活”;节点列表,php,xpath,domdocument,Php,Xpath,Domdocument,有时,似乎返回的域名列表不是活的 当使用类似子节点的访问时,它是活动的 $children=$doc->getElementsByTagName('body')->item(0)->childNodes; echo $children->length; //7 $children->item(0)->parentNode->removeChild($children->item(0)); echo $children->leng
$children=$doc->getElementsByTagName('body')->item(0)->childNodes;
echo $children->length; //7
$children->item(0)->parentNode->removeChild($children->item(0));
echo $children->length; //6! list is live!
但其他时候,这个名单是不活的
$xpath=new DOMXPath($doc);
$nodes=$xpath->query("//p");
echo $nodes->length; // 7
$nodes->item(0)->parentNode->removeChild($nodes->item(0));
echo $nodes->length; // still 7? Not live.
XPath似乎是罪魁祸首。但如果域名列表不是活动的,为什么还要返回它呢?为什么不在那个点上创建一个数组呢