Question:

A developer is creating a data file to store structured information about books. The file must be self-descriptive, allow custom tags, and ensure that all tags are properly nested and closed. Which of the following XML snippets is well formed?

Show Hint

XML is all about Balance. Every ‘<tag>‘ needs a ‘</tag>‘, and they must be closed in the exact reverse order they were opened (LIFO - Last In First Out).
Updated On: Jul 4, 2026
  • <book><title>XML Guide<title><author>John</author></book>
  • <book><title>XML Guide</title><author>John</author></book>
  • <book><title>XML Guide</author><author>John</title></book>
  • <book><title>XML Guide</title><author>John</book>
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Concept:
XML (eXtensible Markup Language) is a strict data-interchange format. Unlike HTML, which can sometimes be "forgiving" with unclosed tags, XML has rigid rules for being "Well-Formed."

Step 1:
Basic XML Rules.
For an XML snippet to be well-formed:
• Every start-tag must have a corresponding end-tag (case-sensitive).
• Elements must be properly nested (a tag opened inside another must be closed before the outer tag).
• There must be a single root element.

Step 2:
Analyze the errors in other options.

Option A: The <title> tag is "closed" with another start-tag <title> instead of an end-tag </title>.
Option C: This exhibits overlapping/incorrect nesting. The <title> is closed by an </author> tag.
Option D: The <author> tag is never closed, and the <book> root is closed prematurely relative to the author.

Step 3:
Confirm the correct choice.
Option B shows perfect syntax. Each opening tag (<book>, <title>, <author>) has a matching closing tag (</book>, </title>, </author>), and the hierarchy is correctly maintained with book as the root.
Was this answer helpful?
0
0