【发布时间】:2016-08-25 02:44:12
【问题描述】:
如何过滤其中包含特定字符串的节点以及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>
假设我想使用QueryPath 删除/删除<link> www.weblink-4.com</link>,您是如何实现的?
我尝试了类似的方法:
$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"?>*
这应该很简单,但变得相当有压力......有什么建议吗?
【问题讨论】: