我正在尝试将子元素附加到预加载的根元素,如下所示
$document = new DOMDocument('1.0', 'UTF-8');
$document->loadXML('<books></books>');
$content = '<books>
<book>
<athors>
<athor>
<name>John Doe</name>
</athor>
</athors>
</book>
</books>';
$books = new DOMDocument()
$books->loadXML($content);
foreach ($books as $book){
$document->appendChild($document->importNode( $book, true ));
}
由于某种原因,结果 xml 文档将如下所示,根元素的结束标记位于文档的开头:
<?xml version="1.0"?>
<books/>
<book>
<athors>
<athor>
<name>John Doe</name>
</athor>
</athors>
</book>
我希望它像下面这样:
<?xml version="1.0"?>
<books>
<book>
<athors>
<athor>
<name>John Doe</name>
</athor>
</athors>
</book>
<books/>
素胚勾勒不出你