如何在PHP中从XML中删除DOM元素?
以下是我的XML文件内容 现在我想从xml中删除如何在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
$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;