Skip to content
Back to all articles
Developer3 min readNovember 15, 2026

How to Open, Read and Validate XML Files (With XPath Examples)

Understand XML structure, find and fix common errors, explore files as a tree, query them with XPath and convert XML to JSON.

How to Open, Read and Validate XML Files (With XPath Examples) article
In this guide
  1. XML in 60 seconds
  2. How to open an XML file
  3. The most common XML errors
  4. Convert XML to JSON
  5. Real-world examples
  6. Large files
  7. Quick checklist

XML files are everywhere: sitemaps, RSS feeds, invoices, Android apps, GPS tracks and older APIs. Opened in a basic editor they look like a wall of angle brackets. This guide explains how to read them, fix errors and find what you need with the free XML Viewer & Validator.

XML in 60 seconds

xml


  
    <title>The Guide</title>
    299
  
  • Elements are the tags: ….
  • Attributes sit inside the opening tag: id="b1".
  • Text sits between the tags: The Guide.
  • There is exactly one root element (catalog) that contains everything else.

How to open an XML file

Paste the XML into the XML Viewer, or open or drop the file (.xml, .xsd, .svg, .rss, .kml, .gpx, .plist and more). It is shown as a collapsible tree: open and close branches to explore, with tags, attributes and text in different colours. Switch to Formatted for neatly indented text, or JSON to see it as JSON.

The most common XML errors

The viewer checks the file immediately and shows the line and column of the first problem.

ErrorCauseFix
Opening and ending tag mismatchA tag was closed in the wrong order or not at allClose tags in reverse order of opening
Unescaped &A plain & in textWrite &
Unescaped &lt;A &lt; inside textWrite &lt;
Attribute without quotesid=b1id=&quot;b1&quot;
Extra content after the rootTwo top-level elementsWrap them in one root
Content before the declarationSpace or text before 250]Prices above 250
count(//book)The number of books
//book[1]/titleThe first book’s title

If a document declares a default namespace, use //*[local-name()="title"].

Convert XML to JSON

Modern apps usually prefer JSON. The JSON view converts the document with attributes as @name keys, repeated elements as arrays and mixed text as #text. Download it as a .json file.

Real-world examples

  • Sitemaps: check that a sitemap.xml is valid before submitting it to Google. Create one with the XML Sitemap Generator.
  • GPS tracks: count the points in a GPX file with count(//*[local-name()="trkpt"]).
  • APIs: pretty-print a SOAP response and pull out a status field.

Large files

Big exports can contain tens of thousands of elements. The tree view shows the first few thousand nodes so the page stays fast; use XPath to jump straight to what you need instead of scrolling, or collapse branches you don’t need.

Quick checklist

  • One root element.
  • Every tag closed, in the right order.
  • Special characters escaped.
  • Attribute values in quotes.

Open your file in the XML Viewer & Validator, or work with JSON in the JSON Formatter.

Was this article helpful?

Found this guide useful?

Share it with someone who is struggling with the same problem.

Free tool · No sign-up

XML Viewer & Validator

Open, validate and explore XML as a collapsible tree. Pretty-print or minify, run XPath queries and convert XML to JSON, all in your browser.

Open tool

Written by

Hemant Adhikari HemantInsights

Senior Software Engineer · Developer of Toolyconvert

I’m a senior software engineer from Dehradun, India, building websites since 2014. I designed and developed Toolyconvert, from the Next.js front end and headless WordPress back end to the tools themselves, and I review every guide before it goes live.