Code example for DocumentBuilder

Methods: parse, setEntityResolver

0
	public static Document readFile(String file)
		throws ParserConfigurationException, SAXException, IOException 
	{ 
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		builder.setEntityResolver(new NoResolver());
		return builder.parse(file);
	} 
 
 
	/** 
	 * Reads and returns the XML document at the given input stream. 
	 */ 
	public static Document readFile(InputStream stream)
		throws IOException 
	{ 
		try { 
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = factory.newDocumentBuilder();
			builder.setEntityResolver(new NoResolver());
			return builder.parse(stream);