XML Formatter|XML 格式化工具

XML Formatter | XML 格式化工具

XML 格式化工具 XML Formatter

对 XML 进行缩进美化(Pretty Print)与压缩(Minify),帮助你快速阅读结构、定位错误与对比差异。
Beautify (pretty-print) and minify XML for better readability, diffing, and faster debugging.

1. 输入参数 · XML Input

3. 使用说明 · Notes
  • 它解决什么问题? · What is this for?
    当 XML 一行很长、层级复杂、或从日志/接口复制出来“挤在一起”时,人眼很难快速看清结构与父子关系。 本工具把 XML 重新缩进、换行,让结构变得“像目录树一样清晰”,也更适合做差异对比(diff)。
    When XML is a single long line or deeply nested, it is hard to read. This tool re-indents and adds line breaks so the structure becomes clear and diff-friendly.
  • 格式化(Pretty Print) · Pretty format
    适合:排错、阅读、审查配置、复制到文档/博客。
    Tips(中文):如果你看到很多“空白行/奇怪缩进”,可以勾选“去除纯空白文本节点”,让输出更干净。
    Tips (EN): If you see noisy blank text nodes or inconsistent whitespace, enable “Remove whitespace-only text nodes” for cleaner output.
  • 压缩(Minify) · Minify
    适合:把 XML 放到 URL/请求体里测试、节省传输体积、或需要“单行 XML”进行粘贴。
    Best for: sending in requests, reducing payload size, or when you need a single-line XML for quick copy/paste.
  • 常见解析失败原因 · Common parsing errors
    1) 标签不闭合:<a><b></a>(应先关 b)。
    2) 特殊字符未转义:例如文本里出现 &<> 需要正确转义。
    3) 复制时丢了根节点:XML 必须有且仅有一个根元素。
    1) Unclosed or mis-nested tags, 2) unescaped special characters, 3) missing a single root element.
  • 关于隐私 · Privacy
    本工具为纯前端本地运行:你的 XML 不会被上传到服务器(除非你自己把页面部署到线上并另行加入上传逻辑)。
    This is a pure client-side tool. Your XML stays in the browser and is not uploaded anywhere (unless you modify and deploy it with network features).
  • 实用建议(排错效率) · Practical debugging tips
    中文:先“格式化”再查错 → 先看根节点与命名空间(xmlns),再看目标节点路径(例如 /root/items/item)。如果你在对比两份 XML,建议先统一缩进(2 或 4)与换行符(LF/CRLF),再做 diff。
    EN: Format first, then debug → check the root and namespaces (xmlns), then locate target paths. For comparing two XMLs, standardize indent and newline style before diffing.

说明:XML 规范与浏览器 DOM 实现细节会影响序列化结果(例如属性顺序、空白节点处理)。本工具目标是“可读性与调试效率”,不是 100% 保留输入的字面格式。
Note: Serialization may differ from the original (e.g., attribute order, whitespace handling). The goal is readability and debugging efficiency, not byte-for-byte preservation.