xml格式化 java_Java XML格式化程序
xml格式化 java
eXtensive Markup Language (XML) is one of the popular medium for messaging and communication between different applications. Since XML is open source and provides control over data format via DTD and XSDs, it’s widely used across technologies.
扩展标记语言(XML)是用于在不同应用程序之间进行消息传递和通信的流行媒介之一。 由于XML是开源的,并且可以通过DTD和XSD提供对数据格式的控制,因此XML在各种技术中得到了广泛使用。
Few days back, I came across a situation where the third party API was returning Document object and XML message as String. So I wrote this simple class to format the XML with proper indentation and convert Document object to XML String.
几天前,我遇到了这样一种情况,即第三方API正在将Document对象和XML消息返回为String。 因此,我编写了这个简单的类,以使用适当的缩进来格式化XML,并将Document对象转换为XML String。
To use this class, you need Apache that you can download from their website.
要使用此类,您需要Apache ,您可以从其网站下载该类。
Output of the above class is a properly formatted XML String:
上面类的输出是格式正确的XML字符串:
I hope you will find this utility class helpful in formatting XML in Java and converting XML to Document and vice versa.
我希望您会发现该实用程序类有助于在Java中格式化XML并将XML转换为Document,反之亦然。
It’s been many years since I wrote this article, java has evolved a lot and we can format XML string easily using API.
自从我写这篇文章以来已经有很多年了,java已经发展了很多,我们可以使用 API轻松格式化XML字符串。
The output will be the same as earlier, you should use this instead of adding a dependency on any third party API.
输出将与之前的输出相同,您应该使用此输出,而不是添加对任何第三方API的依赖关系。
GitHub Repository.
GitHub Repository下载示例代码。
翻译自: https://www.journaldev.com/71/java-xml-formatter
xml格式化 java
还没有评论,来说两句吧...