站点介绍

Debugging a third-party payment callback, the XML arrived as a single 20,000-plus-character line. Opening it in an editor meant counting nesting levels by cursor position until the eyes glazed - what finally cracked it was pasting the blob into a formatter and seeing the missing close tag at depth four. This page was built after that night: format, minify, errors with coordinates, one tool.
The browser's native DOMParser parses XML fine, but its error report is one word: parsererror. Which line? Which column? What exactly? Nothing. For someone debugging, that is the same as silence.
So this page ships its own parser: character-by-character scanning, tokens for tags/attributes/text/comments/CDATA/PIs, pairing checks at the syntax-tree level. Errors convert positions into line:column coordinates - "3:15 attribute value missing quotes" is information; parsererror is not. DOMParser stays as a second-opinion cross-check, and both must pass before anything is emitted (edge-case insurance).
XML recognizes exactly five predefined entities: lt, gt, amp, apos, quot, plus numeric ones (...; / ...;). and friends belong to HTML - in XML they are undefined entities, and plenty of tools pass them through silently until the browser chokes on open.
This page reports undefined entities with coordinates and tells you which entity it was and which ones XML actually accepts. Inside CDATA sections the rules relax - the whole block is text, preserved verbatim.
Just count along: lines start at 1 counted by newline characters, columns start at 1 counted by characters, pointing at the offending character. For example "3:15 attribute value missing quotes" means around column 15 of line 3 there is an unquoted attribute value. It is the same convention as our JSON tool's errors - fix it, press the button again, and it passes. The browser's native DOMParser only hands you a single parsererror word with no coordinates, which is exactly why this page uses its own parser.
Yes. Comments are preserved verbatim in formatted output (indented to their nesting level), and CDATA sections pass through untouched - the < and & inside them are never modified. Self-closing tags keep their self-closing form instead of being expanded into an open/close pair. Namespace prefixes (ns:tag, xmlns:ns=...) are treated as part of the plain name, so prefixes never get stripped.
No - the round trip is stable: format, minify, format again, and the second output matches the first character for character. The reason is that minification only strips the indentation and newlines that formatting introduced; it never touches tag internals or text content. Whitespace inside text nodes belongs to the content and is preserved as-is. Run three rounds on any input and see for yourself.
Yes. The common errors are all covered: unclosed tags, mismatched close tags, unquoted attribute values, bare ampersands, undefined entities ( and friends are HTML, illegal in XML), illegal name start characters, and misplaced XML declarations. The difference is error quality: DOMParser returns one parsererror string with no coordinates, this page gives line:column. The page also runs DOMParser as a cross-check in parallel - both must pass before output is produced.
No. Formatting, minification and validation all happen inside this device's browser - there is no upload endpoint and it works offline. Only preferences like indent width live in this browser's localStorage; they do not follow you to another device, and "Clear my data" in the footer removes them.
中文版:https://www.9314.cn/tools/xml-formatter/
评论列表 (0条)