Hallo,
ich bin ein kompletter JAVA-Anfänger und habe ein Problem, bei dem ich nicht weiterkomme. Vielleicht kann mir einer von euch weiterhelfen
Ich versuche einen Code zu schreiben, der mithilfe einer Schleife die Ergebnisse einer SRU Suchanfrage nach und nach abruft, gesamt sind es etwa 200600. Ich kann nicht alle Ergebnisse auf einmal oder in großen Paketen abrufen, da der Server sonst überlastet ist und ausfällt. Bisher habe ich diesen Code:
Eclipse meldet keine Fehler, aber wenn ich das Programm laufen lasse erhalte ich eine XML in der nur solche Ergebnisse aufgeführt sind <?xml version="1.0" encoding="utf-8"?>
Die SRU funktioniert, ist also korrekt, wenn auch mit Sicherheit unelegant. Kann mir jemand helfen, den Code so anzupassen, dass ich eine XML bekomme in der die Infos der SRU in Tabellenform stehen, damit ich damit in Open Refine arbeiten kann.
Es wäre toll, wenn jemand eine Lösung hat.
Liebe Grüße
ich bin ein kompletter JAVA-Anfänger und habe ein Problem, bei dem ich nicht weiterkomme. Vielleicht kann mir einer von euch weiterhelfen
Ich versuche einen Code zu schreiben, der mithilfe einer Schleife die Ergebnisse einer SRU Suchanfrage nach und nach abruft, gesamt sind es etwa 200600. Ich kann nicht alle Ergebnisse auf einmal oder in großen Paketen abrufen, da der Server sonst überlastet ist und ausfällt. Bisher habe ich diesen Code:
Java:
package kalliope.abfrage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
// Suchanfrage definieren
String searchQuery = "https://kalliope-verbund.info/sru?version=1.2&operation=searchRetrieve&query=ead.repository.isil=%22DE-2498%22+AND+ead.genre=%22Briefe%22+AND+ead.creator.gnd=%22118501232%22+OR+ead.addressee.gnd=%22118501232%22+OR+ead.creator.gnd=%22141293640%22+OR+ead.addressee.gnd=%22141293640%22+OR+ead.creator.gnd=%22118502751%22+OR+ead.addressee.gnd=%22118502751%22+OR+ead.creator.gnd=%22118502786%22+OR+ead.addressee.gnd=%22118502786%22+OR+ead.creator.gnd=%22116339780%22+OR+ead.addressee.gnd=%22116339780%22+OR+ead.creator.gnd=%22132054736%22+OR+ead.addressee.gnd=%22132054736%22+OR+ead.creator.gnd=%22118507931%22+OR+ead.addressee.gnd=%22118507931%22+OR+ead.creator.gnd=%22118508849%22+OR+ead.addressee.gnd=%22118508849%22+OR+ead.creator.gnd=%22118509683%22+OR+ead.addressee.gnd=%22118509683%22+OR+ead.creator.gnd=%22116158824%22+OR+ead.addressee.gnd=%22116158824%22+OR+ead.creator.gnd=%22118512676%22+OR+ead.addressee.gnd=%22118512676%22+OR+ead.creator.gnd=%22118661779%22+OR+ead.addressee.gnd=%22118661779%22+OR+ead.creator.gnd=%22118514865%22+OR+ead.addressee.gnd=%22118514865%22+OR+ead.creator.gnd=%2211851587X%22+OR+ead.addressee.gnd=%2211851587X%22+OR+ead.creator.gnd=%221033852155%22+OR+ead.addressee.gnd=%221033852155%22+OR+ead.creator.gnd=%22118525956%22+OR+ead.addressee.gnd=%22118525956%22+OR+ead.creator.gnd=%22118526634%22+OR+ead.addressee.gnd=%22118526634%22+OR+ead.creator.gnd=%22118826433%22+OR+ead.addressee.gnd=%22118826433%22+OR+ead.creator.gnd=%22118529374%22+OR+ead.addressee.gnd=%22118529374%22+OR+ead.creator.gnd=%221037763181%22OR+ead.addressee.gnd=%221037763181%22+OR+ead.creator.gnd=%22118098713%22+OR+ead.addressee.gnd=%22118098713%22+OR+ead.creator.gnd=%22103748102X%22+OR+ead.addressee.gnd=%22103748102X%22+OR+ead.creator.gnd=%22116771542%22+OR+ead.addressee.gnd=%22116771542%22+OR+ead.creator.gnd=%22118695045%22+OR+ead.addressee.gnd=%22118695045%22+OR+ead.creator.gnd=%22118695894%22+OR+ead.addressee.gnd=%22118695894%22+OR+ead.creator.gnd=%22119129388%22+OR+ead.addressee.gnd=%22119129388%22+OR+ead.creator.gnd=%22118541579%22+OR+ead.addressee.gnd=%22118541579%22+OR+ead.creator.gnd=%22118818058%22+OR+ead.addressee.gnd=%22118818058%22+OR+ead.creator.gnd=%22119138824%22+OR+ead.addressee.gnd=%22119138824%22+OR+ead.creator.gnd=%22118544675%22+OR+ead.addressee.gnd=%22118544675%22+OR+ead.creator.gnd=%22118701797%22+OR+ead.addressee.gnd=%22118701797%22+OR+ead.creator.gnd=%22118544551%22+OR+ead.addressee.gnd=%22118544551%22+OR+ead.creator.gnd=%22118709542%22+OR+ead.addressee.gnd=%22118709542%22+OR+ead.creator.gnd=%22116770058%22+OR+ead.addressee.gnd=%22116770058%22+OR+ead.creator.gnd=%2211855042X%22+OR+ead.addressee.gnd=%2211855042X%22+OR+ead.creator.gnd=%22118550578%22+OR+ead.addressee.gnd=%22118550578%22+OR+ead.creator.gnd=%22118551523%22+OR+ead.addressee.gnd=%22118551523%22+OR+ead.creator.gnd=%22119208768%22+OR+ead.addressee.gnd=%22119208768%22+OR+ead.creator.gnd=%22118706675%22+OR+ead.addressee.gnd=%22118706675%22+OR+ead.creator.gnd=%22116734507%22+OR+ead.addressee.gnd=%22116734507%22+OR+ead.creator.gnd=%2211855610X%22+OR+ead.addressee.gnd=%2211855610X%22+OR+ead.creator.gnd=%22118557327%22+OR+ead.addressee.gnd=%22118557327%22+OR+ead.creator.gnd=%22118558587%22+OR+ead.addressee.gnd=%22118558587%22+OR+ead.creator.gnd=%22120204614%22+OR+ead.addressee.gnd=%22120204614%22+OR+ead.creator.gnd=%22116011092%22+OR+ead.addressee.gnd=%22116011092%22+OR+ead.creator.gnd=%22118560395%22+OR+ead.addressee.gnd=%22118560395%22+OR+ead.creator.gnd=%22118559192%22+OR+ead.addressee.gnd=%22118559192%22+OR+ead.creator.gnd=%22118559206%22+OR+ead.addressee.gnd=%22118559206%22+OR+ead.creator.gnd=%22118560867%22+OR+ead.addressee.gnd=%22118560867%22+OR+ead.creator.gnd=%22116144998%22+OR+ead.addressee.gnd=%22116144998%22+OR+ead.creator.gnd=%22118561715%22+OR+ead.addressee.gnd=%22118561715%22+OR+ead.creator.gnd=%22118710087%22+OR+ead.addressee.gnd=%22118710087%22+OR+ead.creator.gnd=%22115641068%22+OR+ead.addressee.gnd=%22115641068%22+OR+ead.creator.gnd=%22122810937%22+OR+ead.addressee.gnd=%22122810937%22+OR+ead.creator.gnd=%22118564722%22+OR+ead.addressee.gnd=%22118564722%22+OR+ead.creator.gnd=%22118713698%22+OR+ead.addressee.gnd=%22118713698%22+OR+ead.creator.gnd=%22118565486%22+OR+ead.addressee.gnd=%22118565486%22+OR+ead.creator.gnd=%2211871595X%22+OR+ead.addressee.gnd=%2211871595X%22+OR+ead.creator.gnd=%22119023415%22+OR+ead.addressee.gnd=%22119023415%22+OR+ead.creator.gnd=%22112655491%22+OR+ead.addressee.gnd=%22112655491%22+OR+ead.creator.gnd=%22118569368%22+OR+ead.addressee.gnd=%22118569368%22+OR+ead.creator.gnd=%22118570951%22+OR+ead.addressee.gnd=%22118570951%22+OR+ead.creator.gnd=%22118571338%22+OR+ead.addressee.gnd=%22118571338%22+OR+ead.creator.gnd=%22118571990%22+OR+ead.addressee.gnd=%22118571990%22+OR+ead.creator.gnd=%22117041874%22+OR+ead.addressee.gnd=%22117041874%22+OR+ead.creator.gnd=%22120131080%22+OR+ead.addressee.gnd=%22120131080%22+OR+ead.creator.gnd=%2211857633X%22+OR+ead.addressee.gnd=%2211857633X%22+OR+ead.creator.gnd=%22118579266%22+OR+ead.addressee.gnd=%22118579266%22+OR+ead.creator.gnd=%22118783602%22+OR+ead.addressee.gnd=%22118783602%22+OR+ead.creator.gnd=%22122105397%22+OR+ead.addressee.gnd=%22122105397%22+OR+ead.creator.gnd=%22119128640%22+OR+ead.addressee.gnd=%22119128640%22+OR+ead.creator.gnd=%22118742337%22+OR+ead.addressee.gnd=%22118742337%22+OR+ead.creator.gnd=%22118641689%22+OR+ead.addressee.gnd=%22118641689%22+OR+ead.creator.gnd=%22118594524%22+OR+ead.addressee.gnd=%22118594524%22+OR+ead.creator.gnd=%22118787624%22+OR+ead.addressee.gnd=%22118787624%22+OR+ead.creator.gnd=%22118599194%22+OR+ead.addressee.gnd=%22118599194%22+OR+ead.creator.gnd=%22128593709%22+OR+ead.addressee.gnd=%22128593709%22+OR+ead.creator.gnd=%22118601172%22+OR+ead.addressee.gnd=%22118601172%22+OR+ead.creator.gnd=%22117231126%22+OR+ead.addressee.gnd=%22117231126%22+OR+ead.creator.gnd=%22117276413%22+OR+ead.addressee.gnd=%22117276413%22+OR+ead.creator.gnd=%22118608436%22+OR+ead.addressee.gnd=%22118608436%22+OR+ead.creator.gnd=%22107502763%22+OR+ead.addressee.gnd=%22107502763%22+OR+ead.creator.gnd=%22118616145%22+OR+ead.addressee.gnd=%22118616145%22+OR+ead.creator.gnd=%22118751980%22+OR+ead.addressee.gnd=%22118751980%22+OR+ead.creator.gnd=%22118798383%22+OR+ead.addressee.gnd=%22118798383%22+OR+ead.creator.gnd=%221144990866%22+OR+ead.addressee.gnd=%221144990866%22+OR+ead.creator.gnd=%22118619217%22+OR+ead.addressee.gnd=%22118619217%22+OR+ead.creator.gnd=%22118619322%22+OR+ead.addressee.gnd=%22118619322%22+OR+ead.creator.gnd=%22118619977%22+OR+ead.addressee.gnd=%22118619977%22+OR+ead.creator.gnd=%22118620959%22+OR+ead.addressee.gnd=%22118620959%22+OR+ead.creator.gnd=%22118840150%22+OR+ead.addressee.gnd=%22118840150%22+OR+ead.creator.gnd=%22118763520%22+OR+ead.addressee.gnd=%22118763520%22+OR+ead.creator.gnd=%22117468401%22+OR+ead.addressee.gnd=%22117468401%22+OR+ead.creator.gnd=%22118628186%22+OR+ead.addressee.gnd=%22118628186%22+OR+ead.creator.gnd=%22118806440%22+OR+ead.addressee.gnd=%22118806440%22+OR+ead.creator.gnd=%2211862993X%22+OR+ead.addressee.gnd=%2211862993X%22+OR+ead.creator.gnd=%22117297550%22+OR+ead.addressee.gnd=%22117297550%22+OR+ead.creator.gnd=%22118632361%22+OR+ead.addressee.gnd=%22118632361%22+OR+ead.creator.gnd=%22123609240%22+OR+ead.addressee.gnd=%22123609240%22+OR+ead.creator.gnd=%22118634666%22+OR+ead.addressee.gnd=%22118634666%22+OR+ead.creator.gnd=%22118637304%22+OR+ead.addressee.gnd=%22118637304%22+OR+ead.creator.gnd=%22138215928%22+OR+ead.addressee.gnd=%22138215928%22&maximumRecords=200600&recordSchema=dc";
// Anzahl der gefundenen Treffer ermitteln
int totalResults = 200600;
// Dateinamen festlegen
String fileName = "Kalliope_Abfrage.xml";
// XML-Dokument auf dem Schreibtisch speichern
String desktopPath = System.getProperty("user.home") + "/Desktop/";
BufferedWriter writer = new BufferedWriter(new FileWriter(desktopPath + fileName));
// In 50er-Schritten alle Treffer abrufen
for (int startIndex = 1; startIndex <= totalResults; startIndex += 50) {
// Anfrage an SRU senden und Ergebnis in XML-Dokument speichern
URL url = new URL(searchQuery + "&startRecord=" + startIndex + "&maximumRecords=50");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(connection.getInputStream());
BufferedReader reader = new BufferedReader(inputStreamReader);
String line;
while ((line = reader.readLine()) != null) {
writer.write(line);
}
}
// Datei schließen
writer.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Eclipse meldet keine Fehler, aber wenn ich das Programm laufen lasse erhalte ich eine XML in der nur solche Ergebnisse aufgeführt sind <?xml version="1.0" encoding="utf-8"?>
Die SRU funktioniert, ist also korrekt, wenn auch mit Sicherheit unelegant. Kann mir jemand helfen, den Code so anzupassen, dass ich eine XML bekomme in der die Infos der SRU in Tabellenform stehen, damit ich damit in Open Refine arbeiten kann.
Es wäre toll, wenn jemand eine Lösung hat.
Liebe Grüße