Java 怎么从inputstream读取xml节点

2019年8月8日20:41:01Java 怎么从inputstream读取xml节点已关闭评论 1,072 685字阅读2分17秒

1.简介

Java 怎么从inputstream读取xml节点?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import java.io.File;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Node;

public class Main {
    protected static Node read(InputStream xml) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(xml).getDocumentElement();
    }

    protected static Node read(File xml) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(xml).getDocumentElement();
    }
}

 
编程十万个怎么办