Home >php教程 >php手册 >php DOMDocument removeChild 删除节点函数

php DOMDocument removeChild 删除节点函数

WBOY
WBOYOriginal
2016-05-25 16:41:421256browse

本款教程实例是一款利用了 DOMDocument 的getElementById查询到指定的经删除节点,然后用removeChildm删除指定xml节点bi.

php DOMDocument removeChild 删除节点函数实例代码如下:

public function deletecomment($id) { 
  $xml = new domdocument(); 
  $xml->validateonparse=true; 
  $xml->loadxml($this->getcontents(true)); 
  $message = $xml->getelementbyid($id); 
  $parentnode = $message->parentnode; 
  $parentnode->removechild($message); 
  $this->putcontents($xml->savexml()); 
}

xml 文档:

<?xml version="1.0" encoding="utf-8" 
<!doctype messages [ 
<!element messages (message)*> 
<!element message (name , website? , comment , date , user_ip? , user_agent? , spam)> 
<!attlist message mid id #required> 
<!element name (#pcdata)> 
<!element website (#pcdata)> 
<!element comment (#pcdata)> 
<!element date (#pcdata)> 
<!element spam (#pcdata)> 
<!element user_ip (#pcdata)> 
<!element user_agent (#pcdata)> 
]> 
<messages> 
</messages>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn