简体   繁体   English

带有PHP DOMDocument的xml空标签

[英]xml empty tags with PHP DOMDocument

$xmlFile="<test>WPUBON</test>
    <test1>SAPRTA</test1>
    <test2></test2>
    <test3></test3> ";

I have a String as above and i'm parsing this using PHP DOMDocuments 我有一个如上所述的字符串,我正在使用PHP DOMDocuments对此进行解析

$xml = new DOMDocument("1.0", "UTF-8");
$xml->loadXML($xmlFile);
$xml->save("out/".$xmlFileName.".xml");

The output of empty tags comes as </test2> which i need to be <test2></test2> due to the application which process this xml needed as that. 空标记的输出为</test2> ,由于需要处理该xml的应用程序,因此我必须为<test2></test2>

Please let me know a way to do this ! 请让我知道一种方法!

Check the manual page of DOMDocument::save() . 检查DOMDocument::save()的手册页。 It supports the option LIBXML_NOEMPTYTAG . 它支持选项LIBXML_NOEMPTYTAG Try this: 尝试这个:

$xml->save("out/".$xmlFileName.".xml", LIBXML_NOEMPTYTAG );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM