I have a question regarding addChild in SimpleXMLElement. Just a clarifing one.

This piece of code:

$Xml = new SimpleXMLElement("<test></test>");
$Xml->addChild("child");
echo $Xml->asXML();

produces:

<?xml version="1.0"?> <test><child/></test>

My question is why it doesnt produce this?->

<?xml version="1.0"?> <test><child></child></test>

If I give "child" some value it shows up correctly. Im just trying to figure out why it works this way and if I have to worry about that.

Thank you all for the input.

有帮助吗?

解决方案

If there's no contents in the tag there is no point to having the full notation. It's just a simple optimization.

There's nothing to worry about.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top