免费的 XML 格式化工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/193728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Free XML Formatting tool
提问by Saif Khan
Is there a free XML formatting (indent) tool available where I can past an XML string and have it formatted so I can read the XML document correctly?
是否有免费的 XML 格式化(缩进)工具,我可以在其中传递 XML 字符串并对其进行格式化,以便我可以正确读取 XML 文档?
Thanks
谢谢
Edit ~ I am using XML Notepad on Windows XP.
编辑 ~ 我在 Windows XP 上使用 XML 记事本。
回答by Guy
I believe that Notepad++has this feature.
我相信Notepad++有这个功能。
Edit (for newer versions)
Install the "XML Tools" plugin (Menu Plugins, Plugin Manager)
Then run: Menu Plugins, Xml Tools, Pretty Print (XML only - with line breaks)
编辑(对于较新版本)
安装“XML 工具”插件(菜单插件、插件管理器)
然后运行:菜单插件、Xml 工具、漂亮打印(仅限 XML - 带换行符)
Original answer (for older versions of Notepad++)
原始答案(对于旧版本的 Notepad++)
Notepad++ menu: TextFX -> HTML Tidy -> Tidy: Reindent XML
Notepad++ 菜单:TextFX -> HTML Tidy -> Tidy: Reindent XML
This feature however wraps XMLs and that makes it look 'unclean'. To have no wrap,
但是,此功能包装了 XML,这使它看起来“不干净”。没有包裹,
- open
C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI, - find the entry
[Tidy: Reindent XML]and addwrap:0so that it looks like this:
- 打开
C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI, - 找到条目
[Tidy: Reindent XML]并添加wrap:0,使其看起来像这样:
[Tidy: Reindent XML] input-xml: yes indent:yes wrap:0
回答by Ash
Firstobject's free XML editor for Windows is called foxeis a great tool.
Firstobject 为 Windows 提供的免费 XML 编辑器被称为 foxe,是一个很棒的工具。
Open or paste your XML into it and press F8 to indent (you may need to set the number of indent spaces as it may default to 0).
打开或粘贴您的 XML 并按 F8 缩进(您可能需要设置缩进空格数,因为它可能默认为 0)。
It looks simple, however it contains a custom written XML parser written in C++ that allows it to work efficiently with very large XML fileseasily (unlike some expensive "espionage" related tools I've used).
它看起来很简单,但是它包含一个用 C++ 编写的自定义编写的 XML 解析器,这使它能够轻松有效地处理非常大的 XML 文件(与我使用的一些昂贵的“间谍”相关工具不同)。
From the product page:
从产品页面:
The full Visual C++ source code for this firstobject XML editor (including the CDataEdit gigabyte edit control MFC component) is available as part of the Advanced CMarkup Developer License. It allows developers to implement custom XML handling functions such as validation, transformation, beautify, and reporting for their own purposes.
此 firstobject XML 编辑器(包括 CDataEdit 千兆字节编辑控件 MFC 组件)的完整 Visual C++ 源代码作为高级 CMarkup 开发人员许可证的一部分提供。它允许开发人员为自己的目的实现自定义 XML 处理功能,例如验证、转换、美化和报告。
回答by Franci Penov
You can open the XML file in any Visual Studio Express product and the press Ctrl+A, Ctrl+K, Ctrl+Fto get it nicely formatted.
您可以在任何 Visual Studio Express 产品中打开 XML 文件,然后按Ctrl+ A、Ctrl+ K、Ctrl+F以将其格式化。
Hey, it's free and it's a tool, so it fits the question. :-)
嘿,它是免费的,它是一个工具,所以它适合这个问题。:-)
回答by Maksym Kozlenko
Another method to reindent XML in Notepad++:
在 Notepad++ 中重新缩进 XML 的另一种方法:
From menu select Plugins -> XML Tools -> Pretty print (XML only – with line breaks)
or press Ctrl+Alt+Shift+B.
从菜单中选择插件 -> XML 工具 -> 漂亮打印(仅限 XML - 带换行符)
或按Ctrl+ Alt+ Shift+ B。
回答by Ole Bille
You could also try http://xmltoolbox.appspot.com/it is an online xml formatter. You just paste your xml into a large text area field and press "format xml" then it pretty prints the xml in the text area so its easy to read or copy.
您也可以尝试http://xmltoolbox.appspot.com/它是一个在线 xml 格式化程序。您只需将您的 xml 粘贴到一个大文本区域字段中,然后按“格式化 xml”,然后它就会在文本区域中漂亮地打印 xml,以便于阅读或复制。
There is also a nice little filter feature that allows you to see all of a certain element.
还有一个不错的小过滤器功能,可让您查看某个元素的所有内容。
Hope you will enjoy the tool
希望你会喜欢这个工具
回答by Ole Bille
If you use Notepad++, I would suggest installing the XML Toolsplugin. You can beautify any XML content (indentation and line breaks) or linarize it. Also you can (auto-)validate your file and apply XSL transformation to it.
如果您使用 Notepad++,我建议您安装XML Tools插件。您可以美化任何 XML 内容(缩进和换行符)或对其进行线性化。您也可以(自动)验证您的文件并对其应用 XSL 转换。
Download the latest zip and copy the extracted DLL to the plugins directory of your Notepad++ installation. Also, download the External libs and copy them to your %SystemRoot%\system32\ directory.
下载最新的 zip 并将提取的 DLL 复制到 Notepad++ 安装的插件目录中。此外,下载外部库并将它们复制到您的 %SystemRoot%\system32\ 目录。
回答by pgfearo
Advanced Conventional Formatting[Update]
高级常规格式[更新]
XMLSpectrumis an open source syntax-highlighter. Supporting XML - but with special features for XSLT 2.0, XSD 1.1 and XPath 2.0. I'm mentioning this here because it also has special formatting capabilities for XML: it vertically aligns attributes and their contents as well as elements - to enhance XML readability.
XMLSpectrum是一个开源语法高亮器。支持 XML - 但具有 XSLT 2.0、XSD 1.1 和 XPath 2.0 的特殊功能。我在这里提到这一点是因为它还具有特殊的 XML 格式化功能:它垂直对齐属性及其内容以及元素 - 以增强 XML 可读性。
The output HTML is suitable for reviewing in a browser or if the XML needs further editing it can be copied and pasted into an XML editor of your choice
输出 HTML 适合在浏览器中查看,或者如果 XML 需要进一步编辑,可以将其复制并粘贴到您选择的 XML 编辑器中
Because xmlspectrum.xsluses its own XML text parser, all content such as entity references and CDATA sections are preserved - as in an editor.
因为xmlspectrum.xsl使用它自己的 XML 文本解析器,所以所有内容(例如实体引用和 CDATA 部分)都被保留 - 就像在编辑器中一样。


Note on usage: this is just an XSLT 2.0 stylesheet so you would need to enclose the required command-line (samples provided) in a small script so you could automatically transform the XML source.
使用注意事项:这只是一个 XSLT 2.0 样式表,因此您需要将所需的命令行(提供的示例)包含在一个小脚本中,以便您可以自动转换 XML 源。
Virtual Formatting
虚拟格式化
XMLQuireis a free XML editor that has special formatting capabilities - it formats XML properly, including multi-line attributes, attribute-values, word-wrap indentation and even XML comments.
XMLQuire是一个免费的 XML 编辑器,它具有特殊的格式化功能——它可以正确地格式化 XML,包括多行属性、属性值、自动换行缩进甚至 XML 注释。
All XML indentation is done without inserting tabs or spaces, ensuring the integrity of the XML is maintained. For versions of Windows later than XP, no installation is needed, its just a 3MB .exe file.
所有 XML 缩进都是在不插入制表符或空格的情况下完成的,确保保持 XML 的完整性。对于 XP 以后的 Windows 版本,不需要安装,它只是一个 3MB 的 .exe 文件。
If you need to print out the formatted XML there are special options within the print-preview, such as line-numbering that follows the indentation. If you need to copy the formatted XML to a word processor as rich text, that's available too.
如果您需要打印格式化的 XML,则打印预览中有特殊选项,例如缩进后的行编号。如果您需要将格式化的 XML 作为富文本复制到文字处理器,这也是可用的。
[Disclosure: I maintain both XMLQuire and XMLSpectrum as 'home projects']
[披露:我将 XMLQuire 和 XMLSpectrum 都维护为“家庭项目”]
回答by Mihai Limb??an
Not directly an answer, but good to know nevertheless: After indenting, please make sure that the parser(s) and application(s) which will subsequently process the formatted XML will not yield different results. White space is often significant in XMLand most conforming parsers bubble it up to the application.
不是直接的答案,但很高兴知道:缩进后,请确保随后处理格式化 XML 的解析器和应用程序不会产生不同的结果。空格在 XML 中通常很重要,大多数符合标准的解析器会将它冒泡到应用程序中。
回答by JohnnySoftware
If you are a programmer, many XML parsing programming libraries will let you parse XML, then output it - and generating pretty printed, indented output isan output option.
如果您是一名程序员,许多 XML 解析编程库将让您解析 XML,然后输出它 - 并生成漂亮的打印、缩进的输出是一个输出选项。

