Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

$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.

Please let me know a way to do this !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check the manual page of DOMDocument::save(). It supports the option LIBXML_NOEMPTYTAG. Try this:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...