Skip to main content
XMLDir

Search 309 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

XML sitemap

<loc>

The URL itself — the only required child of <url>, and the element where ampersands in query strings go wrong.

<loc> holds an absolute URL including the scheme, and it must be entity-escaped like any other XML text. That is the whole trap: a perfectly ordinary URL with two query parameters contains an ampersand, and an unescaped ampersand starts an entity reference. The file then fails to parse at all, which crawlers report as a broken sitemap rather than a broken URL.

The value is also length-limited — 2,048 characters — and must be under the same host and path prefix as the sitemap itself for a crawler to accept it.

What it contains

Nothing — this element holds a value rather than other elements. Its content is text, and the constraints below are what that text has to be.

Cardinality and constraints

Exactly one per <url>.

  • Absolute URL with a scheme: https://example.com/page, never /page.
  • Entity-escape the value. & becomes &amp;, and that applies to every query string with more than one parameter.
  • At most 2,048 characters.
  • Must begin with the same host and path prefix as the sitemap that lists it.

What our validator does

Missing <loc> values are reported as an error, and repeated ones as a duplicate warning. An unescaped ampersand never reaches these checks — the document fails to parse first.

Broken and fixed

Both documents below are well-formed XML — that is the point of this corpus — and both are run through the validator on every test run. The verdicts here are what it returned, not what we expect it to.

broken
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://example.com/a</loc><lastmod>2026-08-10</lastmod></url>
  <url><loc>https://example.com/a</loc><lastmod>2026-08-10</lastmod></url>
</urlset>
1 duplicate URL(s) found.
fixed
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url><loc>https://example.com/a</loc><lastmod>2026-08-10</lastmod></url>
  <url><loc>https://example.com/b</loc><lastmod>2026-08-10</lastmod></url>
</urlset>
No errors. Warnings may remain — a conforming feed can still be missing a self link — but nothing here is wrong.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.