</>
Skip to content
XML lessons (3/29)

XML — Syntax

XML Declaration

<?xml version="1.0" encoding="UTF-8"?>

Root Element

Every XML document must have exactly one root element:

<root>
    <child>Content</child>
</root>

Closing Tags

All tags must be closed:

<paragraph>Text</paragraph>
<empty/>

Case Sensitivity

Tags are case-sensitive:

<p>Lowercase</p>
<P>Uppercase</P>

Nesting

Elements must be properly nested:

<!-- Correct -->
<p><b>Bold text</b></p>

<!-- Incorrect -->
<p><b>Text</p></b>

Attributes

<book genre="fiction" pages="200">

Special Characters

CharacterEntity
<<
>>
&&
""
''
<note>Price: 5 &lt; 10 &amp; 10 &gt; 5</note>

Whitespace

XML preserves whitespace:

<name>
    John
    Doe
</name>

Rules Summary

  1. Must have a root element
  2. Tags must be closed
  3. Tags are case-sensitive
  4. Must be properly nested
  5. Attribute values must be quoted
  6. Special characters must be escaped

Mini Practice

  1. Create a well-formed XML document
  2. Use proper nesting
  3. Escape special characters
  4. Add attributes to elements

Up Next

Continue with Elements — creating XML elements.

Related Topics

Frequently Asked Questions about Syntax

What is Syntax in XML?

Syntax is a fundamental concept in XML. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Syntax?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Syntax.

Why is Syntax important in XML?

Syntax is essential for XML development. Understanding this concept will help you write better code and solve real-world problems more effectively.