Java tutorial
//package com.java2s; /******************************************************************************* * Copyright 2012-2015 eBay Software Foundation * This program is dual licensed under the MIT and Apache 2.0 licenses. * Please see LICENSE for more information. *******************************************************************************/ import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.InputSource; public class Main { private static Element loadRootElement(InputStream inputStream) throws Exception { // Get XML document from the URL DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //as a default, set validating to false factory.setValidating(false); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource inputSource = new InputSource(inputStream); Document doc = builder.parse(inputSource); return doc.getDocumentElement(); } }