0

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?

2
  • 1
    <students></students> and <students /> are equivalent. It is an XML shorthand when the element has no children. Once you append more children into the root, it should automatically expand. Commented Jun 5, 2016 at 14:43
  • @Xen Thanks, did not know that. Commented Jun 5, 2016 at 14:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.