How to prevent self closing tag in php simplexml

前端 未结 5 1146
忘掉有多难
忘掉有多难 2020-12-03 15:16

I want to generate xml by using php simplexml.

$xml = new SimpleXMLElement(\'\');

$output = $xml->addChild(\'child1\');
$output->addChild(         


        
5条回答
  •  臣服心动
    2020-12-03 15:29

    Despite the quite lengthy answers already given - which are not particularly wrong and do shed some light into some libxml library internals and it's PHP binding - you're most likely looking for:

    $output->noValue = '';
    

    To add an open tag, empty node-value and end tag (beautified, demo is here: http://3v4l.org/S2PKc):

    
    
      
        value
        
      
    
    

    Just noting as it seems it has been overlooked with the existing answers.

提交回复
热议问题