简体   繁体   English

Java将元素追加到XML文档

[英]Java appending an element to XML document

I am trying to append an element to my xml document so it looks like this: 我试图将元素添加到我的xml文档中,所以它看起来像这样:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<students>
</students>

However, it ends up looking like this: 但是,最终看起来像这样:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<students/>

This is the code I am using: 这是我正在使用的代码:

// results is the new XML document I created using DocumentBuilder.newDocument();
Element root = results.createElement("students");
results.appendChild(root);

How come it isn't looking like how I want it to? 怎么看起来不像我想要的那样?

Java dom是根据xml规范实现的,并且根据定义实现:没有内容的元素被认为是空的: https : //www.w3.org/TR/REC-xml/#sec-starttags

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM