我有以下XML(string1):
<?xml version="1.0"?>
<root>
<map>
<operationallayers>
<layer label="Security" type="feature" visible="false" useproxy="true" usePopUp="all" url="http://stackoverflow.com"/>
</operationallayers>
</map>
</root>
Run Code Online (Sandbox Code Playgroud)
我有这段XML(string2):
<operationallayers>
<layer label="Teste1" type="feature" visible="false" useproxy="true" usePopUp="all" url="http://stackoverflow.com"/>
<layer label="Teste2" type="dynamic" visible="false" useproxy="true" usePopUp="all" url="http://google.com"/>
</operationallayers>
Run Code Online (Sandbox Code Playgroud)
我使用函数simplexml_load_string将两者都导入到各自的var:
$xml1 = simplexml_load_string($string1);
$xml2 = simplexml_load_string($string2);
Run Code Online (Sandbox Code Playgroud)
现在,我想为string2的节点'operationslayers'替换string1的节点'operationallayers',但是如何?
SimpleXMLElement类没有像DOM那样的方法'replaceChild'.