ho il seguente codice XML (string1):Come sostituire nodo XML con SimpleXMLElement PHP
<?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>
E ho questo pezzo di 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>
ho usato il funcion simplexml_load_string importare sia alla respectives var:
$xml1 = simplexml_load_string($string1);
$xml2 = simplexml_load_string($string2);
Ora, voglio sostituire il 'operationallayers' nodo del stringa1 per il nodo 'operationallayers' della stringa2, ma come?
La classe SimpleXMLElement non ha un metodo 'replaceChild' come il DOM.
@hakre È possibile farlo funzionare con namespace? – Nightwolf
@hakre Ho creato un wrapper namespace per il mio caso d'uso specifico su $ xml2 ma sarebbe bello averlo incorporato nella classe, se possibile. – Nightwolf