Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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中删除DOM元素?_Php_Xml - Fatal编程技术网

如何在PHP中从XML中删除DOM元素?

如何在PHP中从XML中删除DOM元素?,php,xml,Php,Xml,以下是我的XML文件内容 现在我想从xml中删除元素,我该怎么做呢 $doc = new DOMDocument; $doc->load("XML FILE"); $thedocument = $doc->documentElement; $list = $thedocument->getElementsByTagName('text'); foreach ($list as $domElement){ //Code to remove current text el

以下是我的XML文件内容

现在我想从xml中删除元素,我该怎么做呢

$doc = new DOMDocument; 
$doc->load("XML FILE");
$thedocument = $doc->documentElement;
$list = $thedocument->getElementsByTagName('text');
foreach ($list as $domElement){
    //Code to remove current text element... 
}   

你看过说明书了吗?您可以使用removeChild。美国有一个例子

<?php

$doc = new DOMDocument;
$doc->load('book.xml');

$book = $doc->documentElement;

// we retrieve the chapter and remove it from the book
$chapter = $book->getElementsByTagName('chapter')->item(0);
$oldchapter = $book->removeChild($chapter);

echo $doc->saveXML();
?>
$DOMELENT->parentNode->removeChild$DOMELENT;