我正在构建一个 XML,例如:
<?xml ... ?>
<root>
<elements>0</elements>
<list>
<element>test1</element>
<element>test1</element>
<element>test1</element>
</list>
</root>
附加所有<element>
s 后,我想替换<elements>0</elements>
为<elements>3</elements>
例如。
我试过DOMNode::replaceChild
了,但没有影响。
$numberOfElements = $xml->createElement('numberOfElements', '0');
$root->appendChild($numberOfElements);
/* append elements and count them */
$root->replaceChild($numberOfElements,
$xml->createElement('numberOfElements', $countElements)
);
如何正确使用 replaceChild 还是有不同的方法?