How to prevent self closing tag in php simplexml

前端 未结 5 1139
忘掉有多难
忘掉有多难 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:26

    Since Simple XML is proving troublesome, perhaps XMLWriter could do what you want.

    Here's a fiddle

    openMemory();
    $oXMLWriter->startDocument('1.0', 'UTF-8');
    
    $oXMLWriter->startElement('xml');
    $oXMLWriter->writeElement('child1', 'Hello world!!');
    $oXMLWriter->writeElement('noValue', '');
    $oXMLWriter->endElement();
    
    $oXMLWriter->endDocument();
    echo htmlentities($oXMLWriter->outputMemory(TRUE));
    
    ?>
    

    Output:

    
      
        Hello world!!
        
      
    

提交回复
热议问题