惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
C
Cisco Blogs
博客园 - 叶小钗
P
Privacy International News Feed
Jina AI
Jina AI
Apple Machine Learning Research
Apple Machine Learning Research
T
Threatpost
IT之家
IT之家
博客园 - 聂微东
Know Your Adversary
Know Your Adversary
Help Net Security
Help Net Security
罗磊的独立博客
I
Intezer
S
Schneier on Security
博客园_首页
C
CERT Recently Published Vulnerability Notes
雷峰网
雷峰网
Cisco Talos Blog
Cisco Talos Blog
宝玉的分享
宝玉的分享
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
MyScale Blog
MyScale Blog
P
Privacy & Cybersecurity Law Blog
T
The Exploit Database - CXSecurity.com
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest
H
Heimdal Security Blog
S
Secure Thoughts
Hacker News: Ask HN
Hacker News: Ask HN
Y
Y Combinator Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Microsoft Security Blog
Microsoft Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
SecWiki News
SecWiki News
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
T
Threat Research - Cisco Blogs
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - 庆祝

trigger 来源于:鹰翔宇空的文章 动态判断性别选中的问题 用来在表格中换行 JDK的配置 把struts验证框架的模板翻译成了中文 常用的表查询MSSQL语句 利用JavaEE的Validator Html简单的Head区专业知识 Oracle温习典故 整理的Oracle精辟问答题(8) 整理的Oracle精辟问答题(7) Oracle几个常用的数据字典 ASP.NET的gridview的页脚添加合计字段 ASP.NET把gridview中的数据导入到Excel中 整理的Oracle精辟问答题(6) 整理的Oracle精辟问答题(4) 整理的Oracle精辟问答题(5) 整理的Oracle精辟问答题(3)
可以创建xml的JAVA工厂类--------JAVA
庆祝 · 2008-05-15 · via 博客园 - 庆祝

package com.ajh.xml.util;//任意的包名别忘了改

import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.DOMImplementation;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import java.io.OutputStream;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import org.xml.sax.SAXException;

public class MyDOMUtil {
    //获得一个已有的XML文档
    public static Document getDoc(String xmlPath) throws
            ParserConfigurationException, IOException, SAXException {
        //Builder的工厂
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         //创建一个Builder实例
         DocumentBuilder builder = factory.newDocumentBuilder();

         Document doc = builder.parse(new File(xmlPath));
         return doc;

    }
    //建立一个XML文档
     public static Document getDocWithDocType(String rootElement) throws
             Exception {
         //Builder的工厂
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         //创建一个Builder实例
         DocumentBuilder builder = factory.newDocumentBuilder();
         DOMImplementation docImpl = builder.getDOMImplementation();

         Document doc = docImpl.createDocument(null, rootElement,
                                               null);
         return doc;
     }
      //用JAXP将生DOM对象树输出到输出流中
     public static OutputStream saveToOutputStream(Document doc,
                                                   String encoding,
                                                   OutputStream out) throws
             TransformerConfigurationException, TransformerException {
         //转换工厂
         TransformerFactory tf = TransformerFactory.newInstance();
         //转换器
         Transformer transformer = tf.newTransformer();
         //编码
         transformer.setOutputProperty(OutputKeys.ENCODING, encoding);
         //含有缩进
         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
         //得到要打印得xml文档
         DOMSource source = new DOMSource(doc);
         StreamResult result = new StreamResult(out);
         //进行转换
         transformer.transform(source, result);
         return out;
     }

}