<node-name/>
is just an optimization. If an element node has no child nodes (elements, text, comments, ...). it can be closed directly. For the parser it is the same as <node-name></node-name>
.
The serializer will apply that optimization by default. However if you add an empty string as content you will create a text child node and block the optimization:
$writer = new XMLWriter();
$writer->openURI('php://stdout');
$writer->setIndent(2);
$writer->startDocument();
$writer->startElement('node');
// element with content
$writer->writeElement('element', 'one');
// empty element
$writer->writeElement('another_element');
// element with empty child node
$writer->writeElement('another_element', '');
$writer->endElement();
$writer->endDocument();
Output:
<?xml version="1.0"?>
<node>
<element>one</element>
<another_element/>
<another_element></another_element>
</node>