How to save changed SimpleXML object back to file?

前端 未结 2 1494
迷失自我
迷失自我 2020-12-02 13:35

So, I have this code that searches for a particular node in my XML file, unsets an existing node and inserts a brand new child node with the correct data. Is there a way of

2条回答
  •  青春惊慌失措
    2020-12-02 13:50

    If you want to save the same, you can use dom_import_simplexml to convert to a DomElement and save:

    $dom = new DOMDocument('1.0');
    $dom->preserveWhiteSpace = false;
    $dom->formatOutput = true;
    $dom->loadXML($simpleXml->asXML());
    echo $dom->saveXML();
    

提交回复
热议问题