Kingamere
Kingamere

Reputation: 10146

Java appending an element to XML document

I am trying to append an element to my xml document so it looks like this:

<?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?

Upvotes: 0

Views: 59

Answers (1)

sexybee
sexybee

Reputation: 24

Java dom is implemented based on the xml specification, and by definition: An element with no content is said to be empty : https://www.w3.org/TR/REC-xml/#sec-starttags.

Upvotes: 1

Related Questions