对于免费的XML格式化工具感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解xml在线格式化工具,并且为您提供关于JavaXML格式化,文件到XML,XML到文档、Java8中如何使用预定义的
对于免费的 XML 格式化工具感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解xml在线格式化工具,并且为您提供关于Java XML格式化,文件到XML,XML到文档、Java8中如何使用预定义的格式化工具去解析或格式化日期、Java代码格式化工具、JS XML在线格式化、压缩、校验、XML转JSON工具-toolfk程序员工具网的宝贵知识。
本文目录一览:- 免费的 XML 格式化工具(xml在线格式化工具)
- Java XML格式化,文件到XML,XML到文档
- Java8中如何使用预定义的格式化工具去解析或格式化日期
- Java代码格式化工具
- JS XML在线格式化、压缩、校验、XML转JSON工具-toolfk程序员工具网
免费的 XML 格式化工具(xml在线格式化工具)
是否有可用的免费 XML 格式化(缩进)工具,我可以在其中传递 XML 字符串并对其进行格式化,以便我可以正确读取 XML 文档?
谢谢
编辑 ~ 我在 Windows XP 上使用 XML 记事本。
答案1
小编典典我相信Notepad++有这个功能。
编辑(对于较新版本)
安装“XML 工具”插件(菜单插件、插件管理器)
然后运行:菜单插件、Xml 工具、Pretty Print(仅限 XML - 带换行符)
原始答案(对于旧版本的 Notepad++)
Notepad++ 菜单:TextFX -> HTML Tidy -> Tidy: Reindent XML
然而,这个特性包装了 XML,这使它看起来“不干净”。没有包装,
- 打开
C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI
, 找到条目
[Tidy: Reindent XML]
并添加wrap:0
,使其看起来像这样:[整洁:重新缩进 XML]
输入-xml:是的
缩进:是
换行:0
Java XML格式化,文件到XML,XML到文档
扩展标记语言(XML)是不同应用程序之间的消息传递和通信的流行媒介之一。 由于XML是开源的,并且通过DTD和XSD提供对数据格式的控制,因此它广泛用于各种技术。
Java XML格式化程序
第三方API将Document对象和XML消息作为String返回,这里编写了一个简单的XmlFormatter
类来使用适当的缩进格式化XML并将Document对象转换为XML String。
package com.test.java.xmlutil;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
/**
* Utility Class for formatting XML
* @author Pankaj
*
*/
public class XmlFormatter {
/**
*
* @param unformattedXml - XML String
* @return Properly formatted XML String
*/
public String format(String unformattedXml) {
try {
Document document = parseXmlFile(unformattedXml);
OutputFormat format = new OutputFormat(document);
format.setlinewidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
} catch (IOException e) {
e.printstacktrace();
return ;
}
}
/**
* This function converts String XML to Document object
* @param in - XML String
* @return Document object
*/
private Document parseXmlFile(String in) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(in));
return db.parse(is);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
e.printstacktrace();
}
return null;
}
/**
* Takes an XML Document object and makes an XML String. Just a utility
* function.
*
* @param doc - The DOM document
* @return the XML String
*/
public String makeXMLString(Document doc) {
String xmlString = ;
if (doc != null) {
try {
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();
trans.setoutputProperty(OutputKeys.OMIT_XML_DECLaraTION, yes);
trans.setoutputProperty(OutputKeys.INDENT, yes);
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
xmlString = sw.toString();
} catch (Exception e) {
e.printstacktrace();
}
}
return xmlString;
}
public static void main(String args[]){
XmlFormatter formatter = new XmlFormatter();
String book = <?xml version=\1.0\?><catalog><book id=\bk101\><author>Gambardella, Matthew</author><title>XML Developers Guide</title><genre>Computer</genre><price>44.95</price><publish_date>2000-10-01</publish_date><description>An in-depth look at creating applications with XML.</description></book><book id=\bk102\><author>Ralls, Kim</author><title>Midnight Rain</title><genre>Fantasy</genre><price>5.95</price><publish_date>2000-12-16</publish_date><description>A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.</description></book></catalog>;
System.out.println(formatter.format(book));
}
}
要使用此类,需要Apache xercesImpl.jar
,可以从他们的网站下载。上述类的输出是格式正确的XML字符串:
<?xml version=1.0 encoding=UTF-8?>
<catalog>
<book id=bk101>
<author>Gambardella, Matthew</author>
<title>XML Developers Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications with XML.</description>
</book>
<book id=bk102>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies, an evil
sorceress, and her own childhood to become queen of the world.</description>
</book>
</catalog>
这个实用程序类用于在java中格式化xml并将XML转换为Document,反之亦然。
Java8中如何使用预定义的格式化工具去解析或格式化日期
Java 8中如何使用预定义的格式化工具去解析或格式化日期
package com.shxt.demo02; import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class Demo17 { public static void main(String[] args) { String dayAfterTommorrow = "20180205"; LocalDate formatted = LocalDate.parse(dayAfterTommorrow, DateTimeFormatter.BASIC_ISO_DATE); System.out.println(dayAfterTommorrow+" 格式化后的日期为: "+formatted); } }
以上就是Java8中如何使用预定义的格式化工具去解析或格式化日期的详细内容,更多请关注php中文网其它相关文章!
Java代码格式化工具
有没有这样的java代码格式化工具,可以配置格式化后方法的排列顺序。
我想格式化成所有方法名是递增的。
比如我有一个类
class Test {
public void aaa() {
}
public void ccc() {
}
public void bbb() {
}
}
格式化以后是:
public class Test {
public void aaa() {
}
public void bbb() {
}
public void ccc() {
}
}
JS XML在线格式化、压缩、校验、XML转JSON工具-toolfk程序员工具网
本文要推荐的[ToolFk]是一款程序员经常使用的线上免费测试工具箱,ToolFk 特色是专注于程序员日常的开发工具,不用安装任何软件,只要把内容贴上按一个执行按钮,就能获取到想要的内容结果。ToolFk还支持 BarCode条形码在线生成、 QueryList采集器、 PHP代码在线运行、 PHP混淆、加密、解密、 Python代码在线运行、JavaScript在线运行、YAML格式化工具、HTTP模拟查询工具、HTML在线工具箱、JavaScript在线工具箱、CSS在线工具箱、JSON在线工具箱、Unixtime时间戳转换、Base64/URL/Native2Ascii转换、CSV转换工具箱、XML在线工具箱、WebSocket在线工具、Markdown 在线工具箱、Htaccess2nginx 转换、进制在线转换、在线加密工具箱、在线伪原创工具、在线APK反编译、在线网页截图工具、在线随机密码生成、在线生成二维码Qrcode、在线Crontab表达式生成、在线短网址生成、在线计算器工具。等20多个日常程序员开发工具,算是一个非常全面的程序员工具箱网站。
網站名稱:ToolFk
網站鏈結:https://www.toolfk.com/
工具链接:https://www.toolfk.com/tool-format-xml
代码教學
本工具[JS实现XML在线格式化、压缩、校验、XML转JSON工具]依赖的代码库为https://github.com/nashwaan/xml-js
STEP 1
STEP 2
核心代码如下
var xt = "", h3OK = 1;
function checkXML(e) {
var t, o, i = e.nodeName;
if ("h3" == i) {
if (0 == h3OK)
return;
h3OK = 0
}
for ("#text" == i && (xt = xt + e.nodeValue + "\n"),
t = e.childNodes.length,
o = 0; o < t; o++)
checkXML(e.childNodes[o])
}
xml_2_json:function(options){
if (toolfk.beautify_default.beautify_in_progress) {
return;
}
var opts = $.extend({},toolfk.beautify_default, options);
var source = opts.source.getValue();
if(source==''''){
return layer.msg(NOT_EMPTY);
}
if(source.indexOf(''encoding="UTF-8"'')<0){
source = ''''+source;
}
toolfk.beautify_default.beautify_in_progress = true;
var lastResult = xml2json(source, {compact: true, spaces: 4});
opts.target.setValue(lastResult);
toolfk.report(''xml_2_json'',lastResult);
toolfk.beautify_default.beautify_in_progress = false;
},
beautify_xml:function(options){
if (toolfk.beautify_default.beautify_in_progress) {
return;
}
var opts = $.extend({},toolfk.beautify_default, options);
var source = opts.source.getValue();
if(source==''''){
return layer.msg(NOT_EMPTY);
}
toolfk.beautify_default.beautify_in_progress = true;
var value= format(source,{method: ''xml''});
opts.target.setValue(value);
toolfk.report(''beautify_xml'',value);
toolfk.beautify_default.beautify_in_progress = false;
},
值得一試的三個理由:
-
整合各種程序员开发中经常使用的开发测试工具。
-
简洁美观大气的网站页面
-
支持 在线格式化执行代码、APK在线反编译、在线高强度密码生成、在线网页截图 等二十多種工具服务
-
同时还推荐一下它的姐妹网 www.videofk.com 视频下载工具箱
本文链接:http://www.hihubs.com/article/372
我们今天的关于免费的 XML 格式化工具和xml在线格式化工具的分享就到这里,谢谢您的阅读,如果想了解更多关于Java XML格式化,文件到XML,XML到文档、Java8中如何使用预定义的格式化工具去解析或格式化日期、Java代码格式化工具、JS XML在线格式化、压缩、校验、XML转JSON工具-toolfk程序员工具网的相关信息,可以在本站进行搜索。
本文标签: