随笔 - 16  文章 - 22  trackbacks - 0
<2016年6月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

常用链接

留言簿(3)

我参与的团队

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

使用JAVA自带dom包(org.w3c.dom)时,想写入doctype
<!DOCTYPE alert PUBLIC "SYSTEM" "TEST.dtd">




百度不可靠,搜半天没找到,google下就OK了

TransformerFactory transformerFactory 
= TransformerFactory.newInstance();
Transformer transformer 
= transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, 
"yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, 
"no");
transformer.setOutputProperty(OutputKeys.METHOD, 
"xml");
DOMImplementation domImpl 
= document.getImplementation();
DocumentType doctype 
= domImpl.createDocumentType("doctype",
"SYSTEM",
"TEST.dtd");
transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId());
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId());
DOMSource source 
= new DOMSource(document);
StreamResult result 
= new StreamResult(new File(database));
transformer.transform(source, result);






posted on 2015-07-09 11:43 rapin 阅读(592) 评论(1)  编辑  收藏

FeedBack:
# re: JAVA自带DOM包操作XML 2016-06-30 16:24 ttt
还是google好用 百度太垃圾了   回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: