Skip to content
DeviceCheckHub

XML Formatter and Validator

A free XML beautifier and viewer: paste XML to pretty print it, minify it, check it or browse it in a tree. Mistakes are shown with the exact line and column, and you can convert it to JSON or find parts of it with XPath.

Paste or open some XML and it is checked and formatted here. Nothing is uploaded.

Type an XPath such as //book/title to list the matching parts of your XML.

    How to format and check XML

    1. Paste your XML into Your XML, or press Open a file to load an .xml, .svg, .rss, .xsd, .config or other text file. You can also drag a file onto the box. Try an example fills it for you.
    2. The tool checks the text while you type. If it is well-formed, you see Well-formed XML, the formatted result on the right and a count of the elements, attributes and levels inside it.
    3. If something is wrong, the box on the right shows the lines around the mistake with a marker under the exact spot, and the message says what is wrong and how to fix it in plain words. Go to the mistake puts your cursor there.
    4. Choose how to see the result, then press Copy result or Download. Use result for my text moves the result back into the left box so you can keep editing it.

    Formatted, minified, tree and JSON

    The most common XML mistakes

    XML is strict: a program must refuse a document with even one mistake in it. These are the mistakes people make most often, and the tool names each one with its line and column:

    Your text is kept exactly

    Many formatters read the XML into a program and write it back out, and that round trip can quietly change it: entities are replaced by characters, attribute quotes change, CDATA sections turn into escaped text and spaces inside text are trimmed. This formatter copies every text, attribute value, comment, CDATA section and processing instruction exactly the way you wrote it, and only changes the spacing between tags. It also knows where spacing matters. In an element that mixes text and tags, such as <p>Press <b>Save</b> now</p>, the spaces around the tag are part of the text, so that element is left untouched; the same goes for anything inside an element marked xml:space="preserve".

    Find parts of the document with XPath

    XPath is a short language for pointing at parts of an XML document, used in XSLT, test tools, web scrapers and many programming libraries. Type an expression under Find with XPath and the matches are listed while you type. A few examples for the sample document:

    Where you meet XML

    XML is still everywhere behind the scenes: SOAP web services, payment messages in the ISO 20022 standard, RSS and Atom news feeds, sitemaps for search engines, SVG images, Office documents (a .docx file is a zip of XML files), Android layouts, Maven and .NET project files, and GPX tracks from GPS devices. When one of those fails to load, a stray character or an unclosed tag is usually the cause, and formatting the file is the quickest way to see its structure and find the line.

    Tips

    Your XML stays on your device

    XML often holds private data, so everything happens in your browser: the checking, formatting, minifying, tree, JSON and XPath all run on your own computer or phone, and nothing is sent to this website or anyone else. The page remembers your latest text, XPath and settings in your browser on this device so they survive a reload. Clear removes the text, and clearing the site’s data in your browser removes everything.

    Frequently asked questions

    Is my XML uploaded to a server?

    No. Checking, formatting, the tree, the JSON conversion and XPath all run in your browser, so nothing you paste or open is sent anywhere. That makes it safe for XML with private data, such as invoices, configuration files or SOAP messages. The page keeps your last text on this device so it is still there after a reload; press Clear to remove it.

    What is the difference between well-formed and valid XML?

    Well-formed XML follows the grammar every XML document must follow: one root element, every tag closed and nested correctly, attribute values in quotes, and special characters written with references. This tool checks exactly that. Valid XML is well-formed and also matches a schema (an XSD or DTD) that says which elements may appear where. Checking against a schema needs that schema file, which this page does not ask for.

    Does formatting change my data?

    No. Text, attribute values, comments and CDATA sections are copied character for character. The tool only adds or removes the line breaks and indentation between tags. Where spaces can matter, it leaves them alone: an element that mixes text with tags, such as a paragraph with a bold word, and any element marked xml:space="preserve", are kept exactly as written.

    Why does it say a prefix is not declared?

    A name such as soap:Envelope uses the namespace prefix soap, and XML namespaces require that prefix to be declared with an attribute such as xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" on that element or one around it. Web browsers and namespace-aware parsers such as expat refuse a document with an undeclared prefix, so the tool reports it with the line and column.

    How does the XML to JSON conversion work?

    Each element becomes a key. Attributes become keys that start with @, text becomes the value, or a #text key when the element also has attributes or child elements, and a child element that appears more than once becomes a list. Every value is text, because XML has no numbers or true and false; a program reading the JSON decides what each value means.

    Which XPath can I use?

    XPath 1.0, the version built into web browsers, with all its functions such as count(), contains() and local-name(). Prefixes declared in your document work in the expression. An element in a default namespace (declared with a plain xmlns="…") has no prefix to write, so match it with //*[local-name()="title"].

    How big a file can it handle?

    A file you open can be up to 5 MB, and pasting works for similar sizes. A few megabytes of XML is checked and formatted in well under a second on a normal computer. The tree shows the first 500 children of each element and XPath lists the first 100 matches, to keep the page quick; the text views show everything.

    Last updated · About DeviceCheckHub