WEB-DEVELOPMENT-FOUNDATION practice question 15 of 15

What is an example of a self-closing XML tag?

Full set: 75 questions
Answer options
A:

A. <testx/test>

B:

B. </test>

C:

C. <testxtest>

D:

D. <test />

Correct answer
Correct Answer:
D. D. <test />
Explanation

In XML (Extensible Markup Language), a self-closing tag, also known as an empty-element tag, is used for elements that do not contain any content between an opening and closing tag. The syntax for a self-closing tag is . It combines the start-tag and end-tag into a single tag by placing a forward slash (/) immediately before the closing angle bracket (>). Option D, , correctly follows this required syntax.

Why Incorrect

A. is invalid XML syntax. The forward slash is misplaced, and the start and end identifiers within the tag do not match.
B. is a standard closing tag. It is used to mark the end of an element that has a separate opening tag and typically contains content.
C. is a standard opening tag. It would require a corresponding closing tag, such as , to form a complete element.

References

1. W3C, Extensible Markup Language (XML) 1.0 (Fifth Edition) Recommendation:

Section 3.1, Start-Tags, End-Tags, and Empty-Element Tags: The specification defines the syntax for an EmptyElemTag as ''. This formal definition directly matches the structure of . The document states, "Empty-element tags may be used for any element which has no content..."

2. MDN Web Docs, XML basics:

Section: The basic rules of XML: This document explains, "For elements that have no content, you can use a self-closing tag. For example, is a valid XML element." This confirms that a tag ending with /> is the correct format for a self-closing element.

3. MIT OpenCourseWare, 6.005 Software Construction, Reading 19: Taming the World with XML:

Section: XML Syntax: The course material illustrates XML syntax, showing examples of empty elements like . This demonstrates the standard practice and syntax for self-closing tags in an academic context.

Scroll to Top