<node-name/>只是一个优化。如果元素节点没有子节点(元素、文本、评论等)。可以直接关闭。对于解析器,它与<node-name></node-name>.默认情况下,序列化程序将应用该优化。但是,如果您添加一个空字符串作为内容,您将创建一个文本子节点并阻止优化:$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();输出:<?xml version="1.0"?><node> <element>one</element> <another_element/> <another_element></another_element></node>