我正在尝试将一个元素附加到我的 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);
为什么它看起来不像我想要的那样?
最佳答案
Java dom 是基于 xml 规范实现的,根据定义:没有内容的元素被称为空元素:https://www.w3.org/TR/REC-xml/#sec-starttags .
关于Java 将元素附加到 XML 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37643119/