XML Syntax Rules
XML (Extensible Markup Language) follows strict syntax rules to ensure well-formed documents.
1. XML Must Have a Root Element
Every XML document must have a single root element that contains all other elements.
<library>
<book>
<title>XML Basics</title>
<author>John Doe</author>
</book>
</library>
<library>
is the root element.- All other elements are nested inside it.
2. XML Tags Must Be Properly Closed
XML elements must have opening and closing tags. ✅ Correct:
<title>XML Guide</title>
❌ Incorrect:
<title>XML Guide <!-- Missing closing tag -->
3. XML Tags Are Case-Sensitive
✅ Correct:
<Title>XML Guide</Title>
❌ Incorrect:
<Title>XML Guide</title> <!-- Case mismatch -->
<Title>
and<title>
are different elements.
4. XML Elements Must Be Properly Nested
✅ Correct:
<book>
<title>XML Basics</title>
<author>John Doe</author>
</book>
❌ Incorrect:
<book>
<title>XML Basics
<author>John Doe</title> <!-- Incorrect nesting -->
</author>
</book>
- The
<author>
tag must be inside<book>
but outside<title>
.
5. XML Attribute Values Must Be Quoted
✅ Correct:
<book title="XML Basics" author="John Doe"/>
❌ Incorrect:
<book title=XML Basics author=John Doe/> <!-- Missing quotes -->
- Attribute values must be enclosed in quotes (
""
or''
).
6. XML Allows Self-Closing Tags
If an element has no content, you can use a self-closing tag:
<book title="XML Basics"/>
This is equivalent to:
<book title="XML Basics"></book>
7. XML Supports Comments
Comments in XML are written like this:
<!-- This is a comment -->
<book>
<title>XML Basics</title>
</book>
❌ Incorrect:
<!-- This is a comment --!> <!-- Wrong syntax -->
8. XML Does Not Allow Special Characters Without Escaping
Some characters have special meanings and must be escaped: | Character | Escape Code |
0 comments:
Post a Comment