public static Element parse ( InputSource source ) throws IOException { try { Document doc ; DocumentBuilder builder = getDocumentBuilder ( ) ; synchronized ( builder ) //synchronize to prevent concurrent parsing on the same DocumentBuilder { doc = builder . parse ( source ) ; } return doc . getDocumentElement ( ) ; } catch ( SAXException se ) { throw new IOException ( se . toString ( ) ) ; } finally { InputStream is = source . getByteStream ( ) ; if ( is != null ) { is . close ( ) ; } Reader r = source . getCharacterStream ( ) ; if ( r != null ) { r . close ( ) ; } } }
Parse the given input source and return the root Element . This uses the document builder associated with the current thread .