Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top