ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

XML Tutorial• 6 min read

XML Introduction & Core Syntax Rules

The prolog, root element, case-sensitivity, and well-formedness

XML (eXtensible Markup Language) is a W3C recommendation designed to store and transport structured data in a software- and hardware-independent format.

The 5 Non-Negotiable Syntax Rules of XML

1Single Root Element: Every XML document must have exactly one root element enclosing all other elements.
2All Tags Must Close: Unlike forgiving HTML <p> or <img>, every XML tag must close (<item></item> or <item/>).
3XML is Case-Sensitive: <Book> and <book> are completely different tags.
4Proper Nesting: Overlapping tags are strictly illegal (<b><i></b></i> will crash any XML parser).
5Attribute Values Must Be Quoted: Attributes must always be enclosed in single or double quotes (<user id="42">).
A Well-Formed XML Document
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <course id="cs-101">
    <title>Modern Web Development</title>
    <instructor>Dr. Alan Turing</instructor>
    <price currency="USD">49.99</price>
  </course>
</catalog>
Contains prolog declaration, root <catalog>, closed tags, and quoted attributes.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which of the following is a strict syntax violation in XML that makes a document not well-formed?