<xml>
<ns:foo attribute="bar">
OLD TEXT DATA
</ns:foo>
</xml>
我使用XPath来处理XML命名空间。这不起作用:
$xml->asXML('old.xml');
foreach ($xml->xpath('ns:foo') as $foo) {
$foo['attribute'] = 'new bar';
$foo = 'NEW TEXT DATA'; //This won't be saved by asXML().
}
$xml->asXML('new.xml');
如何使用SimpleXMLElement::xpath
更改文字内容?
答案 0 :(得分:0)
$xml->asXML('old.xml');
foreach ($xml->xpath('ns:foo') as $foo) {
$foo['attribute'] = 'new bar';
$foo[0] = 'NEW TEXT DATA';
}
$xml->asXML('new.xml');