【发布时间】:2016-10-05 05:11:55
【问题描述】:
我正在尝试将一个元素附加到我的 xml 文档中,所以它看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<students>
</students>
然而,它最终看起来像这样:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<students/>
这是我正在使用的代码:
// results is the new XML document I created using DocumentBuilder.newDocument();
Element root = results.createElement("students");
results.appendChild(root);
为什么看起来不像我想要的样子?
【问题讨论】:
-
和 是等价的。当元素没有子元素时,它是一种 XML 简写。将更多子项添加到根目录后,它应该会自动展开。 -
@Xen 谢谢,不知道。