如何过滤其中包含特定字符串的节点和Delete
/或Remove
它。
就像是
XML
就像:
<?xml version="1.0"?>
<user>
<urls>
<link>www.weblink-1.com</link>
<link> www.weblink-2.com</link>
<link> www.weblink-3.com</link>
<link> www.weblink-4.com</link>
<link> www.weblink-5.com</link>
</urls>
</user>
假设我想<link> www.weblink-4.com</link>
使用QueryPath
您如何实现删除/删除?
我试过类似的东西:
$r= qp($path,'user')->find("urls>link")->
filter("link:contains('<link> www.weblink-4.com</link>')");
print "<h1>".$r."</h1>";
///***ERROR: Catchable fatal error:
Object of class QueryPath\DOMQuery could not be converted to string*
我也尝试过类似的东西:
$r= qp($path,'user')->find("urls>link:contains('<link> www.weblink-4.com</link>')");
print "<h1>".$r."</h1>";
///***ERROR: Catchable fatal error:
Object of class QueryPath\DOMQuery could not be converted to string*
然后是这样的:
$qp = qp($path,'user>urls>link')->filter("link:contains('<link> www.weblink-4.com</link>')")->remove();
$qp->writeXML($path);
///This Deletes the entire Document's nodes leaving only the *<?xml version="1.0"?>*
这应该很简单,但变得非常有压力......有什么建议吗?