Home > php教程 > php手册 > body text

php DOMDocument removeChild 删除节点函数

WBOY
Release: 2016-05-25 16:41:42
Original
1204 people have browsed it

本款教程实例是一款利用了 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()); 
}
Copy after login

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>
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!