Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP XML删除父项_Php_Xml - Fatal编程技术网

PHP XML删除父项

PHP XML删除父项,php,xml,Php,Xml,XML: 此代码仅删除了节点,如何更改它以删除父节点 我不知道怎么做,我只是设法摆脱了title节点并获得了大量错误代码,而这可能是我使用xpath的原因,您可以找到 $title = $_GET['0']; $xml = new DOMDocument('1.0', 'ISO-8859-1'); $xml->formatOutput = true; $xml->preserveWhiteSpace = true; $xml->load($location); $pages

XML:

此代码仅删除了
节点,如何更改它以删除父
节点


我不知道怎么做,我只是设法摆脱了title节点并获得了大量错误代码

,而这可能是我使用xpath的原因,您可以找到

$title = $_GET['0'];

$xml = new DOMDocument('1.0', 'ISO-8859-1');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = true;
$xml->load($location);
$pages = $xml->getElementsByTagName("page");
foreach($pages as $page){
    $pagetitle = $page->getElementsByTagName("title");
    $pagetitlevalue = $pagetitle->item(0)->nodeValue;
    if($title == $pagetitlevalue){
        $pagetitle->item(0)->parentNode->removeChild($pagetitle->item(0));
    }
}
$xml->save($location);
并替换为

$pagetitle->item(0)->parentNode->removeChild($pagetitle->item(0));

要想在XML树中再上一层

你能稍微修改一下你的问题吗,这样我就可以撤销我的意外否决票了?@Scuzzy已经有一段时间了,但你来了哈哈
$pagetitle->item(0)->parentNode->removeChild($pagetitle->item(0));
$pagetitle->item(0)->parentNode->parentNode->removeChild($pagetitle->item(0)->parentNode);