public static WMSEndpoint parse ( InputStream inputStream ) throws Exception { DocumentBuilderFactory dbFactory = DocumentBuilderFactory . newInstance ( ) ; DocumentBuilder dBuilder = dbFactory . newDocumentBuilder ( ) ; dBuilder . setEntityResolver ( new EntityResolver ( ) { @ Override public InputSource resolveEntity ( String publicId , String systemId ) throws SAXException , IOException { return new InputSource ( new StringReader ( "" ) ) ; } } ) ; Document doc = dBuilder . parse ( inputStream ) ; Element element = doc . getDocumentElement ( ) ; element . normalize ( ) ; if ( element . getNodeName ( ) . contains ( "WMT_MS_Capabilities" ) ) { return DomParserWms111 . parse ( element ) ; } else if ( element . getNodeName ( ) . contains ( "WMS_Capabilities" ) ) { return DomParserWms111 . parse ( element ) ; } throw new IllegalArgumentException ( "Unknown root element: " + element . getNodeName ( ) ) ; }
note the input stream remains open after calling this method closing it is the caller s problem