FIELD NOTES · SEARCH EVIDENCE

Preserve the exact URL when writing sitemap XML

Two encodings, two different jobs

A supplier copies a valid address containing query parameters into a sitemap. The browser address contains an ampersand, while the XML source needs an escaped representation. Another supplier encodes the entire URL again and changes an existing percent escape. Both files may look plausible in a text editor, but the important question is which exact address an XML reader obtains.

Keep the approved address outside the serializer

The sitemap protocol requires UTF-8 and entity escaping of values. Our exercise starts with already approved, already URL-encoded addresses and checks only their XML representation. It does not choose canonical pages, repair malformed business URLs or decode query values. Those decisions belong upstream. The original input list is retained as the comparison, rather than reconstructed from the candidate output.

Replay the filled address pair

The synthetic first address is https://cedar.example/services/?area=inner%20north&kind=fitout. Its XML text contains & between the two parameters, while the percent escape remains %20. Parsing the XML must recover the original address exactly. The second address includes the query value A%2BB and a quoted label. It tests that the plus encoding and quote characters survive the same round trip. Neither address is a live customer destination.

Challenge the plausible failures

A raw ampersand can make the XML fail to parse. Replacing it twice can produce a valid XML file whose parsed URL contains the literal characters amp; in the query. Replacing %20 with %2520 can also leave the XML valid while changing the address. These are separate failures: parsing is necessary, but equality with the approved URL list is what detects the latter two. Do not accept a green parser badge as a content-preservation result.

Run the finite local check

Download roundtrip.py, filled-input.json and test_roundtrip.py into one folder. With Python 3.10 or newer, run the two commands below. The supplied program creates XML, parses it and compares the ordered URL list. Its tests cover raw ampersands, double escaping, altered percent escapes, missing entries and quoted characters. Empty lists, credentials in URLs and malformed percent escapes are rejected under this teaching contract. No network request or sitemap submission occurs.

Separate syntax from publication acceptance

For a real handover, retain the approved URL inventory, generator version, exact output bytes and parsed comparison result. Then independently check file location, host authority, size limits, indexability and the actual published response. The small program is deliberately not a complete sitemap validator and cannot determine whether Google read or indexed a URL. It also cannot authorise a change to an existing address or sitemap.

Filled review cases

All examples are synthetic teaching records, not client results or live search measurements. Scroll the table on narrow screens.

InputOutputInterpretation
A · Approved query URL serialised onceEXACT_URL_ROUNDTRIPCompare parsed loc with the original string
B · Raw ampersand in candidate XMLXML_PARSE_FAILEDPreserve malformed output for diagnosis
C · Double-escaped ampersandURL_LIST_MISMATCHValid XML can still change the address
D · %20 replaced by %2520URL_LIST_MISMATCHDo not encode the entire approved URL again

Deliver the evidence

  1. Approve complete URL strings before generating XML.
  2. Serialize once, parse the result and compare against the unchanged input list.
  3. Keep actual publication and search processing as separate checks.

Sitemaps protocol documentation · Supporting passages checked 6 November 2026. Case labels and review procedures are our original teaching design; they are not Google certification rules.

filled-review.json · README.txt · roundtrip.py · filled-input.json · actual-output.json · test_roundtrip.py

python3 -B roundtrip.py filled-input.json
python3 -B -m unittest -v test_roundtrip.py

Continue with the related, separately scoped review.