I'm using an existing XMLReader code in my project for taking elements from an XML page. It works fine for only one element like this:
public String getURL(String Url) {
BufferedReader br = null;
try {
URL url = new URL(Url);
br = new BufferedReader(new InputStreamReader(url.openStream()));
String line;
StringBuilder sb= new StringBuilder();
while ((line = br.readLine()) != null) {
if(line.contains("presentationURL")) {
line = line.split("<presentationURL>")[1].split("</presentationURL>")[0];
sb.append(line);
sb.append(System.lineSeparator());
}
}
return sb.toString();
... But when I try to add a second element right after here:
if(line.contains("presentationURL")) {
line = line.split("<presentationURL>")[1].split("</presentationURL>")[0];
sb.append(line);
sb.append(System.lineSeparator());
}
like this:
if(line.contains("manufacturer")) {
line = line.split("<manufacturer>")[1].split("manufacturer")[0];
sb.append(line);
sb.append(System.lineSeparator());
}
the program gives me Array Index Out of Bounds Exception and some other errors. How can I make this program work for more elemets?