SAX Parsing in Java

最后都变了- 提交于 2019-12-12 03:27:15

问题


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?


回答1:


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);



回答2:


This should help SAX parser and a file from the nework

The important line being

xr.parse(new InputSource(sourceUrl.openStream()));

where sourceUrl is a string



来源:https://stackoverflow.com/questions/19399621/sax-parsing-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!