java setxmlstandalone()是哪个类的,Document的setXmlStandalone()方法不生效

public void test() throws ParserConfigurationException {

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();

DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

Document doc = docBuilder.newDocument();

doc.setXmlStandalone(true); //无效

Element request = doc.createElement("request");

Element sn = doc.createElement("sn");

Element user = doc.createElement("user");

Element passwd = doc.createElement("passwd");

Element args = doc.createElement("args");

Element arg1 = doc.createElement("arg");

arg1.setAttribute("name", "arg1");

Element arg2 = doc.createElement("arg");

arg2.setAttribute("name", "arg2");

Element arg3 = doc.createElement("arg");

arg3.setAttribute("name", "arg3");

sn.setTextContent("201601011234567890");

user.setTextContent("XXXX");

passwd.setTextContent("XXXX");

arg1.setTextContent("Y");

arg2.setTextContent("YY");

arg3.setTextContent("YYY");

doc.appendChild(request);

request.appendChild(sn);

request.appendChild(user);

request.appendChild(passwd);

request.appendChild(args);

args.appendChild(arg1);

args.appendChild(arg2);

args.appendChild(arg3);

System.out.println(XmlTools.docToStr(doc, true));

}

输出结果

201601011234567890

XXXX

XXXX

Y

YY

YYY

我是想要standalone="yes"的,但是用doc.setXmlStandalone(true)方法行不通

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值