更新时间:2023-11-06 20:57:22
SimpleXML 没有移除子节点的功能,
有些情况下你可以做如何删除一个元素在 XML 字符串中?
但取决于 XML 结构
SimpleXML does not have the remove child node feature,
there are cases you are can do How to deleted an element inside XML string?
but is depend on XML structure
DOMDocument 中的解决方案
$doc = new DOMDocument;
$doc->loadXML($noteString['Notes']);
$xpath = new DOMXPath($doc);
$items = $xpath->query( 'note[@url!="http://yahoo.com"]');
for ($i = 0; $i < $items->length; $i++)
{
$doc->documentElement->removeChild( $items->item($i) );
}