Search code examples
javasax

SAX Parsing in Java


I must parse an XML from URL in Java with SAX parser. I didn't find an example on the internet about this topic. All of them are reading an XML from local. Is there an example that xml has nested tags and parsing from url in Java?


Solution

  • Refer this example java snippet

            String webServiceURL="web service url or document url here";
            URL geoLocationDetailXMLURL = new URL(webServiceURL);
            URLConnection geoLocationDetailXMLURLConnection = geoLocationDetailXMLURL.openConnection();
            geoLocationDetailXMLURLConnection.setConnectTimeout(120000);
            geoLocationDetailXMLURLConnection.setReadTimeout(120000);
            BufferedReader geoLeocationDetails = new BufferedReader(new InputStreamReader(geoLocationDetailXMLURLConnection.getInputStream(), "UTF-8"));
            InputSource inputSource = new InputSource(geoLeocationDetails);
            saxParser.parse(inputSource, handler);