Docs / Formats
XML
Last updated:
Prettify opens, validates, and pretty-prints XML in your browser, and converts it to JSON, YAML, and CSV. It reads RSS and Atom feeds. SVG has its own page: see SVG. This page explains the XML behavior. For feeds, see RSS and Atom feeds.
Open the editor at /app/editor, or start from the XML Formatter tool page.
How Prettify detects XML
Prettify reads text as XML when it starts with < and parses as a well-formed document. A .xml, .xhtml, .xsl, or .xslt file opens as XML too. An SVG file does not open as XML. It opens as SVG, with an Image view. To read SVG text as XML, pick XML in the format list. Prettify then shows an empty XML tab. Paste the SVG text into that tab.
You can also set the format by hand in the sidebar or the Command Palette. Open the Command Palette with Cmd+K (Mac) / Ctrl+K (Windows, Linux).
Attributes and the data model
Prettify turns the XML tree into keys and values for the Tree, Table, and Diagram views. An attribute is stored under a key with an @ prefix. Repeated child tags become an array. Text inside an element with attributes is stored under #text.
<book id="b1">
<title>Dune</title>
<tag>sci-fi</tag>
<tag>classic</tag>
</book>
The example reads as one book object, with @id set to b1 and two tag values in an array.
Views
XML gets these views. Tree, Raw, and Table are free.
| View | What it shows |
|---|---|
| Tree | A collapsible tree of elements, attributes, and text. The default view. |
| Raw | The pretty-printed XML, with line numbers and inline problems. |
| Table | Repeated elements as rows and columns. |
| Diagram (Pro) | A node graph with collapsible nodes. |
| Feed (Pro) | RSS and Atom items as articles. Only for a feed document. |
The Feed view appears only when the document is an RSS, Atom, or RSS 1.0 feed, and a feed opens on it by default. See RSS and Atom feeds, Diagram view, and Views.
Formatting
Prettify pretty-prints XML with two-space indentation. The Raw view shows this formatted text. Copy Formatted copies it, and Download saves it.
Validation and error messages
Prettify checks that the XML is well formed. A parse error carries a line and column, read from the browser parser. The Problems panel also shows lint notes:
- An information note when the XML declaration (
<?xml version="1.0"?>) is missing. - A warning for a duplicate attribute in the same tag.
Query with XPath
XPath (Pro) selects nodes with the browser XPath engine (XPath 1.0). It supports namespace prefixes.
//book[@id='b1']/title
See XPath queries. jq is for JSON and SQL is for CSV, so XML uses XPath.
Convert
Convert turns XML into JSON, JSONL, YAML, or CSV. XML to JSON writes each attribute as an @attribute key, which Prettify notes in the warning.
Converting other data to XML has two rules. A key that is not a valid XML element name is renamed, and Prettify lists the renamed keys. A single-item array becomes one element and reloads as a single value, not an array, which Prettify also notes. See Conversion.
Diff / Compare (Pro) compares two documents; see Diff. Pro is a one-time purchase of US$19.99. See Pro.
Privacy
Parsing, formatting, and conversion run on your device. Prettify does not upload your XML unless you share it. See Privacy and Sharing.
Try it online
Tool pages for this topic. Each one runs in your browser.