mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix xml format
This commit is contained in:
parent
281341ebd7
commit
b07571d398
@ -587,6 +587,7 @@ public class XmlUtil {
|
||||
final Transformer xformer = factory.newTransformer();
|
||||
if (indent > 0) {
|
||||
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
//fix issue#1232@Github
|
||||
xformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "yes");
|
||||
xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.map.MapBuilder;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import lombok.Data;
|
||||
@ -9,6 +10,8 @@ import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
@ -226,4 +229,38 @@ public class XmlUtilTest {
|
||||
private String ProjectCode;
|
||||
private String BankCode;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void formatTest(){
|
||||
// https://github.com/looly/hutool/pull/1234
|
||||
Document xml = XmlUtil.createXml("NODES");
|
||||
xml.setXmlStandalone(true);
|
||||
|
||||
NodeList parentNode = xml.getElementsByTagName("NODES");
|
||||
|
||||
Element parent1Node = xml.createElement("NODE");
|
||||
|
||||
Element node1 = xml.createElement("NODENAME");
|
||||
node1.setTextContent("走位");
|
||||
Element node2 = xml.createElement("STEP");
|
||||
node2.setTextContent("1");
|
||||
Element node3 = xml.createElement("STATE");
|
||||
node3.setTextContent("2");
|
||||
Element node4 = xml.createElement("TIMELIMIT");
|
||||
node4.setTextContent("");
|
||||
Element node5 = xml.createElement("STARTTIME");
|
||||
|
||||
parent1Node.appendChild(node1);
|
||||
parent1Node.appendChild(node2);
|
||||
parent1Node.appendChild(node3);
|
||||
parent1Node.appendChild(node4);
|
||||
parent1Node.appendChild(node5);
|
||||
|
||||
parentNode.item(0).appendChild(parent1Node);
|
||||
|
||||
String format = XmlUtil.toStr(xml,"GBK",true);
|
||||
Console.log(format);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user