Leon Chaewon Kong's dev blog

[TIL] Sitemap.xml

sitemap.xml sometimes plays essential role, like SEO(Search Engine Optimization), and implementing Google Adsense.

Let’s find out to create a valid sitemap.


<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

These are the basic form of a sitemap.

  • urlset encapsulates the file.
  • url is a parent tag for each URL entity.
  • loc is the actual URL string.

There are other tags like lastmod, changefreq

See sitemaps.org - ‘XML tag definitions’ section


The URL string must be encoded properly. You can use JavaScript encodeURI() to handle this.

Characters like &, ', ", >, < must be properly escaped.

Character Escape Code
Ampersand & &
Single Quote ‘ '
Double Quote “ "
Greater Than > >
Less Than < <

The URL string must start with protocol(http, https). Depends on your web server, URL string must ends with a trailing slash(/).