read XML Node from InputStream - Java XML

Java examples for XML:XML Node

Description

read XML Node from InputStream

Demo Code


//package com.java2s;
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();//  w  ww  .  j a va 2s.  c  o  m
        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();
    }
}

Related Tutorials