Ich präferiere Jakarta Commons HTTPClient.
Eigentlich besteht die Aufgabe aus 2 Teilen:
1. XML als Stream herunterladen
2. Mit einer XML-Api das XML auslesen.
Hier ist ein code Ausschnitt für das herunterladen mit HTTPClient von jakarta commons:
| |
| |
| |
| |
| |
| |
| |
| |
| |
| private InputStream connect(final String url) |
| throws SpiHttpConnectionException { |
| Clogging.debug(getClass().getName() + ".connect(" + url + ")"); |
| |
| method = new GetMethod(url); |
| method.setFollowRedirects(true); |
| |
| method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, |
| new DefaultHttpMethodRetryHandler(HTTP_RETRY, false)); |
| |
| |
| int statusCode; |
| try { |
| statusCode = client.executeMethod(method); |
| |
| if (statusCode != HttpStatus.SC_OK) { |
| String msg = StringUtils.replaceOnce( |
| Constants.EXCEPTION_MSG_HTTP_STATUS, |
| "{param}", "" + statusCode); |
| msg = StringUtils.replaceOnce(msg, "{param}", method |
| .getStatusLine().toString()); |
| Clogging.debug(msg); |
| throw new SpiHttpConnectionException(msg); |
| |
| } |
| return method.getResponseBodyAsStream(); |
| |
| } catch (HttpException e) { |
| |
| throw new SpiHttpConnectionException( |
| |
| StringUtils.replace(Constants.EXCEPTION_MSG_HTTP, |
| "{param}", url)); |
| |
| } catch (IOException e) { |
| throw new SpiHttpConnectionException(StringUtils.replace( |
| Constants.EXCEPTION_MSG_IO, "{param}", url), e); |
| |
| } |
| |
| } |
Für Schritt 2 empfehle ich die XPath features von JDom.
Gruß Axel
P.S.: Je konkreter die Fragen, desto zielführender die Antworten.