Getting SimpleXMLElement to include the encoding in output

前端 未结 5 959
梦如初夏
梦如初夏 2020-12-09 10:26

This:

$XML = new SimpleXMLElement(\"\");
echo($XML->asXML());

...outputs this:



        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 11:06

    Simple and clear only do this

    $XMLRoot = new SimpleXMLElement('');
    

    OutPut

    
          
    

    to add attributes in element only use

    $XMLRoot->addAttribute('name','juan');
    

    to add child use

    $childElement = $XMLRoot->addChild('elementChild');
    $childElement->addAttribute('attribName','somthing');
    

提交回复
热议问题