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

XML — Elements

Basic Elements

<name>John Doe</name>
<age>30</age>

Empty Elements

<br/>
<hr/>
<image src="photo.jpg"/>

Nested Elements

<book>
    <title>My Book</title>
    <author>
        <first>John</first>
        <last>Doe</last>
    </author>
</book>

Element Naming Rules

RuleExample
Start with letter or underscore<name>, <_data>
Can contain letters, digits, hyphens, underscores<first-name>
No spaces or special charactersNot <first name>
No starting with xml/XMLNot <xmlData>

Text Content

<price>29.99</price>
<description>This is a book about XML</description>

Mixed Content

<p>This is <b>bold</b> and <i>italic</i> text.</p>

CDATA Sections

For content with special characters:

<script>
<![CDATA[
    if (x < 10 && y > 5) {
        console.log("Hello");
    }
]]>
</script>

Mini Practice

  1. Create elements with different content types
  2. Use nested elements
  3. Create empty elements
  4. Use CDATA for special content

Up Next

Continue with Attributes — adding attributes to elements.

Related Topics

Frequently Asked Questions about Elements

What is Elements in XML?

Elements 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 Elements?

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 Elements.

Why is Elements important in XML?

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