What this XML editor does
XML (Extensible Markup Language) is a text format for structured data that uses nested, named tags. It's behind sitemaps, RSS and Atom feeds, SOAP web services, SVG images, Maven and Android project files, and the insides of .docx and .xlsx documents. This editor lets you open, change and save XML in the browser with syntax highlighting.
Type an opening tag such as <price> and the matching </price> appears automatically. Long documents are easier to handle with the fold arrows in the gutter, which collapse any element down to a single line. Find / Replace, Word Wrap, Dark Theme, Full Screen, Copy and Download (the file saves as data.xml) are on the toolbar.
What it won't do: check well-formedness, validate against a schema, or pretty-print. The editor colors whatever you type, valid or not. "Checking your XML" below covers the tools for that.
Sample document
This catalog shows the main pieces of XML syntax in one place: the declaration, a namespace prefix, a comment, attributes, an escaped ampersand, a character reference and a CDATA section.
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns:media="http://example.com/ns/media">
<!-- Prices are in EUR -->
<book id="bk101" lang="en">
<title>XML & You</title>
<author>Gambardella, Matthew</author>
<price currency="EUR">44.95</price>
<media:cover src="covers/bk101.jpg"/>
</book>
<book id="bk102" lang="fr">
<title>Le Petit Prince</title>
<author>Saint-Exupéry, Antoine de</author>
<price currency="EUR">9.50</price>
<summary><![CDATA[Use <b> tags freely in here & nothing breaks.]]></summary>
</book>
</catalog>
It parses cleanly, and é comes out as "é" in the second author's name.
Well-formedness rules from the XML 1.0 spec
Every XML parser must stop at the first well-formedness error, so one small slip makes the whole file unreadable. The rules below are from the W3C XML 1.0 (Fifth Edition) recommendation.
| Rule | Broken | Fixed |
|---|---|---|
| Exactly one root element | <a/><b/> |
<root><a/><b/></root> |
| Tags are case-sensitive and must nest properly | <Item><b></Item></b> |
<item><b></b></item> |
| Attribute values are always quoted | <book id=bk101> |
<book id="bk101"> |
| Ampersands and less-than signs in text must be escaped | <t>Tom & Jerry</t> |
<t>Tom & Jerry</t> |
| The declaration comes first, with nothing before it | a blank line, then <?xml ...?> |
<?xml ...?> on line 1 |
XML predefines only five entities: &, <, >, " and '. HTML names like or © are errors unless a DTD declares them; use numeric references such as   instead. Namespace prefixes like media: must be declared with an xmlns: attribute, as required by Namespaces in XML 1.0.
Checking your XML
- Click Download. The file saves as
data.xml; rename it if you like. - Drag the file into Chrome, Firefox or Edge. A well-formed file shows as a document tree; a broken one shows the parser's error with a line and column.
- On the command line,
xmllint --noout data.xml(part of libxml2; preinstalled on macOS, and in thelibxml2-utilspackage on Debian and Ubuntu) prints nothing when the file is well-formed and lists errors when it isn't.
The XML formatter also reports parse errors when you paste XML into it and gives you an indented copy to read.
Related editors
The same editor exists for HTML, which looks similar but follows far more forgiving parsing rules, and for JSON and YAML if you're converting a data format away from XML. All of them are listed on the online code editors page.
Last updated