XML is everywhere even if you never write it by hand. Your website's sitemap is XML. So are RSS and Atom feeds, product feeds for shopping platforms, SVG images, Office documents under the hood, GPS tracks, and countless data exports from older business systems. When one of them breaks, a search engine stops reading your sitemap, a feed reader shows nothing, or an import fails with an unhelpful "invalid XML" message.
This guide explains the building blocks of XML, what "well-formed" means, how to read the most common XML files you are likely to meet, and how to find and fix parse errors quickly.
XML building blocks
An XML document is a tree of elements. Each element has a start tag and an end tag, and can contain text, other elements, or both:
<?xml version="1.0" encoding="UTF-8"?>
<catalog updated="2026-09-01">
<!-- Stock list for the north warehouse -->
<product sku="DESK-01" currency="EUR">
<name>Standing desk</name>
<price>349.00</price>
<notes><![CDATA[Ships flat-packed. Width < 140 cm.]]></notes>
</product>
</catalog>
The pieces:
- XML declaration (
<?xml … ?>): optional first line stating the version and encoding. - Elements (
<product>…</product>): the structure. There must be exactly one root element, here<catalog>. - Attributes (
sku="DESK-01"): name and value pairs on a start tag. Values must be quoted. - Comments (
<!-- … -->): ignored by programs that process the data. - CDATA sections (
<![CDATA[ … ]]>): text that may contain characters like<and&without escaping. - Processing instructions (
<?name … ?>): instructions for specific applications, such as a stylesheet link.
Namespaces
Different vocabularies can use the same tag names. Namespaces keep them apart with a prefix bound to a URI:
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
After this declaration, <g:price> means "price as defined by that namespace". The URI is an identifier, not necessarily a page you can visit. If a prefix is used without being declared, the document is not well-formed.
Well-formed versus valid
These terms are often mixed up:
- Well-formed means the document follows XML's syntax rules: every tag closed, properly nested, one root, quoted attributes, escaped special characters. Any XML parser checks this.
- Valid means it is well-formed and follows a specific schema (an XSD or DTD) that defines which elements are allowed where. A sitemap can be well-formed but still invalid if it uses an element the sitemap schema does not define.
A viewer or browser tells you whether a file is well-formed. Checking validity needs the schema and a validating tool.
Read XML with the XML Viewer
Our XML Viewer parses XML in your browser and shows it as a collapsible tree.
- Open the XML Viewer. A small product feed with a namespace, comments and CDATA is loaded as an example.
- Paste XML into XML input, or click Open .xml file. It accepts
.xml,.rss,.atom,.svg,.xsd,.xsl,.kml,.gpxand.plistfiles up to 20 MB. - If the XML is not well-formed, an XML parse error box shows the parser's message, usually including a line and column. Fix it and the tree appears.
- Browse the tree. Elements show their attributes inline; comments, CDATA sections and processing instructions are shown in their own styles so you can tell them apart from normal text.
- Type in Filter tags, attributes, text… to narrow the tree to matching branches, and use Expand all or Collapse all to reset.
- Check the tiles for the number of Elements, Attributes and the Max depth.
Reading common XML files
XML sitemaps
A sitemap lists the URLs you want search engines to know about:
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/pricing</loc>
<lastmod>2026-09-15</lastmod>
</url>
</urlset>
Filter by a path such as /pricing to confirm a page is listed, and check that every <loc> uses the correct protocol and domain. A sitemap index uses <sitemapindex> and <sitemap> elements that point to further sitemap files. To create one from scratch, use the Sitemap Generator.
RSS and Atom feeds
RSS feeds have a <channel> with <item> elements, each with a title, link, date and description. Descriptions often contain HTML inside CDATA. Collapse all, open the channel, and count the items to confirm new posts appear.
Product and data feeds
Shopping and marketplace feeds usually add namespaced elements such as g:price or g:availability. Filter by the element name to check that every product has it.
Other ways to view XML
Your browser
Opening an XML file in a desktop browser shows either a tree or the raw text, depending on the browser and whether the file links a stylesheet. Browsers also report parse errors. It is quick for files you already have, but offers no filtering.
Code editors
VS Code and similar editors highlight XML, fold elements and, with an extension, validate against a schema. This is the right place to edit files and to check validity, not just well-formedness.
Command line
xmllint (part of libxml2, available on most Linux systems and macOS) checks well-formedness and can validate against a schema:
xmllint --noout sitemap.xml
It is ideal for scripts and very large files.
Fixing parse errors
"Opening and ending tag mismatch"
A tag was closed in the wrong order or not at all. XML is strict: <b><i>text</b></i> is an error. Go to the reported line and check the nesting just above it.
Unescaped ampersands
A bare & in text or a URL (for example ?a=1&b=2) breaks XML. Write it as &, or wrap the text in CDATA. The same applies to < in text, which must be <. The HTML Entity Encoder escapes text for you.
"Content is not allowed in prolog" or junk before the root
Something appears before the XML declaration: a blank line, a byte order mark or stray output from a script. The declaration must be the very first thing in the file.
Undeclared namespace prefix
A tag like <g:price> is used but xmlns:g="…" is missing from an ancestor element. Add the declaration to the root.
Hard to read at all
If the file is a single long line, indent it with the XML Formatter first. If you would rather work with the data as JSON, XML to JSON converts it.
Frequently asked questions
What is the difference between XML and HTML?
HTML is a fixed vocabulary for web pages and browsers tolerate many mistakes in it. XML is a general syntax for any data, with no predefined tags, and parsers reject documents that break its rules.
What is CDATA used for?
CDATA marks a block of text that the parser should not interpret as markup. It is often used to embed HTML inside RSS descriptions without escaping every < and &.
Does the viewer validate my sitemap against the schema?
No. It checks that the XML is well-formed and shows its structure. Use a schema-aware validator or your search engine's webmaster tools to check sitemap validity.
Why does a single ampersand break my XML file?
In XML, & starts an entity reference such as &. A bare ampersand is ambiguous, so the parser stops with an error.
Is my XML file uploaded?
No. The file is parsed by your browser's built-in XML parser and never leaves your device.