XML formatter and XPath tester
Format, minify and validate XML, then query it with XPath. Errors point to the exact line and column.
Reading, formatting and querying XML
XML is still everywhere in enterprise Java: SOAP services, Maven pom files, Spring and Hibernate configuration, Android layouts, payment and banking messages. These documents often arrive as a single unreadable line, or with an error somewhere in a megabyte of tags. This tool pretty-prints or minifies XML, checks that it is well-formed with an exact line and column for the first problem, and lets you test XPath expressions against it.
Format with two spaces, four spaces or tabs. The formatter keeps comments, CDATA sections, the XML declaration and the doctype in place, and puts simple elements such as <title>Effective Java</title> on one line. Switch to the XPath tab to evaluate a query: the matching nodes, strings, numbers or booleans appear below, using your browser's XPath 1.0 engine, the same one family of standard that javax.xml.xpath uses in Java.
Typical error messages
- Closing tag does not match: a tag was closed in the wrong order, or a closing tag is missing.
- Unescaped "&": write
&in text and attribute values. - Text outside the root element: a stray character before or after the document.
- Duplicate attribute: an element repeats the same attribute name.
Namespaces deserve a note: in XPath 1.0 an element in a default namespace cannot be matched by its bare name. Use the local-name() function, or register a prefix in your code. Everything runs in your browser, so internal documents stay internal.
Frequently asked questions
What is XPath?
XPath is a query language for XML. //book/title selects every title inside a book, //book[@id="b2"] selects by attribute, and functions such as count(), sum() and contains() compute over the result. XPath 1.0 is what browsers and Java's built-in javax.xml.xpath support.
What makes XML well-formed?
One root element, every tag closed and correctly nested, quoted attribute values, no duplicate attributes and escaped special characters (&, <). The checker reports the first violation with its line and column.
Does formatting change the meaning of my XML?
It only changes whitespace between elements. Text inside elements is kept, though leading and trailing spaces in mixed content are trimmed, so check documents where whitespace is significant.
Why does my XPath return nothing?
The most common reason is a default namespace: elements in xmlns="..." need a prefix in XPath 1.0, or use //*[local-name()="book"].