How is possible add child to the specific node

前端 未结 3 1529
终归单人心
终归单人心 2021-01-27 05:09

This is my starting xml :

 
    
      
        
     &         


        
3条回答
  •  清歌不尽
    2021-01-27 05:47

    With DOMDocument it's as easy as this:

    $child = new DOMElement('children');
    $parent->appendChild($child);
    

    Whereas $parent is the DOMElement parent which (after you have updated your question) to aquire is part of your problem:

    // append  to the first  element
    $parent = $dom->getElementsByTagName('child')->item(0);
    $child = new DOMElement('children');
    $parent->appendChild($child);
    

提交回复
热议问题