问题
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