本款教程实例是一款利用了 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>
|