Bird
Raised Fist0
SEO Fundamentalsknowledge~10 mins

XML sitemap creation in SEO Fundamentals - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - XML sitemap creation
Start Sitemap Creation
List URLs to include
Create XML structure
Add <url> entries for each URL
Add <loc>, <lastmod>, <changefreq>, <priority> tags
Close XML tags
Save sitemap.xml file
Submit sitemap to search engines
The flow shows how to create an XML sitemap by listing URLs, building XML tags for each, and submitting the file.
Execution Sample
SEO Fundamentals
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
  </url>
</urlset>
This XML snippet creates a sitemap with one URL entry for the homepage.
Analysis Table
StepActionXML Tag CreatedContent AddedResulting XML snippet
1Start XML document<?xml version="1.0" encoding="UTF-8"?>Declaration<?xml version="1.0" encoding="UTF-8"?>
2Open <urlset><urlset>xmlns attribute<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3Add <url> entry<url>Start URL block<url>
4Add <loc><loc>https://example.com/<loc>https://example.com/</loc>
5Close <url></url>End URL block</url>
6Close <urlset></urlset>End sitemap</urlset>
💡 All URLs added and XML tags properly closed, sitemap creation complete.
State Tracker
VariableStartAfter Step 3After Step 4After Step 5Final
XML Content<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url><?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://example.com/</loc><?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://example.com/</loc> </url><?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://example.com/</loc> </url> </urlset>
Key Insights - 3 Insights
Why do we need the xmlns attribute in the <urlset> tag?
The xmlns attribute defines the XML namespace, telling search engines this file follows the sitemap protocol. Without it, the sitemap might not be recognized correctly (see execution_table step 2).
Can we add URLs without the <loc> tag inside <url>?
No, the <loc> tag is required to specify the exact URL. Omitting it means the URL entry is incomplete and ignored by search engines (see execution_table step 4).
What happens if we forget to close the <urlset> tag?
The XML becomes invalid and search engines will reject the sitemap. Proper closing of tags is essential for well-formed XML (see execution_table step 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what content is added inside the <loc> tag?
Ahttps://example.com/home
Bhttp://example.com/
Chttps://example.com/
Dexample.com
💡 Hint
Check the 'Content Added' column at step 4 in execution_table.
At which step is the <url> tag closed in the execution_table?
AStep 4
BStep 5
CStep 3
DStep 6
💡 Hint
Look for the 'XML Tag Created' column showing a closing tag for .
If we add a second URL, how would the variable_tracker's 'XML Content' change after step 5?
AIt would include two <url> blocks before closing </urlset>
BIt would only have one <url> block
CIt would remove the first <url> block
DIt would close <urlset> early
💡 Hint
Refer to variable_tracker showing XML content growth with each URL added.
Concept Snapshot
XML Sitemap Creation:
- Start with XML declaration
- Open <urlset> with xmlns attribute
- Add one <url> block per URL
- Include <loc> tag with full URL
- Close all tags properly
- Save as sitemap.xml and submit to search engines
Full Transcript
Creating an XML sitemap involves starting with an XML declaration, opening the <urlset> tag with the required xmlns attribute, then adding a <url> block for each web page. Each <url> block must contain a <loc> tag specifying the full URL. After adding all URLs, close the <urlset> tag to complete the XML. This sitemap file helps search engines find and index your website pages efficiently.

Practice

(1/5)
1. What is the main purpose of an XML sitemap for a website?
easy
A. To help search engines find and index website pages
B. To improve website design and layout
C. To increase website loading speed
D. To store user data securely

Solution

  1. Step 1: Understand the role of an XML sitemap

    An XML sitemap is a file that lists all important pages of a website to guide search engines.
  2. Step 2: Identify the main benefit

    This helps search engines find and index pages more efficiently, improving site visibility.
  3. Final Answer:

    To help search engines find and index website pages -> Option A
  4. Quick Check:

    XML sitemap purpose = guide search engines [OK]
Hint: Sitemaps list pages for search engines [OK]
Common Mistakes:
  • Confusing sitemap with website design
  • Thinking sitemap speeds up loading
  • Assuming sitemap stores user data
2. Which of the following is the correct root element for an XML sitemap file?
easy
A. <urlset>
B. <sitemap>
C. <site>
D. <pages>

Solution

  1. Step 1: Recall XML sitemap structure

    The root element of an XML sitemap is <urlset>, which contains all URL entries.
  2. Step 2: Compare options

    <sitemap> is used in sitemap index files, <site> and <pages> are not standard sitemap tags.
  3. Final Answer:

    <urlset> -> Option A
  4. Quick Check:

    Root tag for sitemap = <urlset> [OK]
Hint: Sitemap URLs go inside <urlset> tag [OK]
Common Mistakes:
  • Using <sitemap> as root instead of <urlset>
  • Confusing sitemap index with sitemap file
  • Using non-standard tags like <site> or <pages>
3. Given this XML sitemap snippet:
<urlset>
  <url>
    <loc>https://example.com/page1</loc>
    <lastmod>2024-06-01</lastmod>
  </url>
  <url>
    <loc>https://example.com/page2</loc>
  </url>
</urlset>

How many URLs are listed in this sitemap?
medium
A. 1
B. 2
C. 3
D. 0

Solution

  1. Step 1: Count the <url> elements

    The snippet shows two <url> blocks, each representing one URL.
  2. Step 2: Confirm URLs inside each block

    Each <url> contains a <loc> tag with a URL, so total URLs listed are two.
  3. Final Answer:

    2 -> Option B
  4. Quick Check:

    Count <url> tags = 2 [OK]
Hint: Count <url> tags to find URLs listed [OK]
Common Mistakes:
  • Counting <loc> tags incorrectly
  • Confusing <lastmod> as URL
  • Ignoring second <url> block
4. Identify the error in this XML sitemap snippet:
<urlset>
  <url>
    <loc>https://example.com/home</loc>
    <lastmod>2024-06-31</lastmod>
  </url>
</urlset>
medium
A. The <loc> tag should be <location>
B. Missing closing tag for <urlset>
C. The date in <lastmod> is invalid
D. The URL is missing http://

Solution

  1. Step 1: Check the date format in <lastmod>

    The date '2024-06-31' is invalid because June has only 30 days.
  2. Step 2: Verify other tags and URL format

    All tags are properly closed, <loc> is correct, and https:// is valid URL scheme.
  3. Final Answer:

    The date in <lastmod> is invalid -> Option C
  4. Quick Check:

    Invalid date in lastmod tag [OK]
Hint: Check date validity in <lastmod> tag [OK]
Common Mistakes:
  • Assuming <loc> must be <location>
  • Ignoring invalid date format
  • Thinking URL must start with http:// only
5. You want to create an XML sitemap that only includes pages updated in the last 30 days. Which approach is best?
hard
A. Use a sitemap index file pointing to multiple sitemaps without dates
B. List only pages without <lastmod> tags to keep it simple
C. Create a sitemap with all pages and submit it without updates
D. Include all pages and add <lastmod> with the update date, then filter by date before submission

Solution

  1. Step 1: Understand filtering by update date

    To include only recently updated pages, you must track <lastmod> dates and filter accordingly.
  2. Step 2: Choose the correct method

    Including all pages with <lastmod> and filtering before submission ensures search engines see only recent pages.
  3. Final Answer:

    Include all pages and add <lastmod> with the update date, then filter by date before submission -> Option D
  4. Quick Check:

    Filter sitemap by lastmod date before submitting [OK]
Hint: Use <lastmod> dates to filter pages before submitting sitemap [OK]
Common Mistakes:
  • Omitting <lastmod> tags
  • Submitting outdated sitemaps
  • Using sitemap index without filtering