I hope all is well with you guys. I've been messing about with some Java recently, attempting to get data from an XML Link, and parsing the dat I need from it using a BufferedInputStream. I've done some searching here on Stack O.F -- and came up with this link. How to retrieve XML/RDF data from a dbpedia link or URL?
Pretty handy, and a lot of my code is based upon that. Slight problem though, somewhere along the way my program is catching an error. I have no idea why, and I was hoping you guys could help me out.
//import statements;
import java.io.*;
import java.util.Scanner;
import java.net.URL;
import java.net.HttpURLConnection;
import java.net.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String url = "http://http://battlecc5.evony.com/default.html?logfile/20171113/7d/42/7d42c3c3c89a7de4ec58c1ed0e66fbb1.xml";
try{
URL urlObj = new URL(url);
System.out.println("URL Reached");
try{
java.net.HttpURLConnection connection = (HttpURLConnection)urlObj.openConnection();
System.out.println("Connection Successful");
try{
InputStream reader = new BufferedInputStream(connection.getInputStream());
BufferedReader breader = new BufferedReader(new InputStreamReader(reader));
String line;
while((line = breader.readLine()) != null){
System.out.println(line);
}
connection.disconnect();
System.out.println("Closed");
}
catch(IOException e){System.out.println("Fail 1");}
}
catch(IOException e){System.out.println("Fail 2");}
}
catch(MalformedURLException e){System.out.println("Failed 3");}
System.out.println("Reached the End");
}
private boolean isDraftable(int modValue, int input){
boolean success = false; // Default value
int num = (int)(input/modValue);
if((num % 2) == 0){
//Is Even
success = true; // isDraftable(true)
}
else{
success = false; // !isDraftable(true)
}
return success;
}
private void HCDraft(int input){
int draftFive = input/20;
//System.out.println("HC Draft: %d", draftFive);
}
private void CDraft(int input){
int draftTen = input/10;
//System.out.println("Colony Draft: %d", draftTen);
}
}
It isn't complete yet, but once the connection is made, it should just be ouputting what it's finding. Later, I'll be parsing it and doing calculations and whatnot with it (The 3 private functions are there for this purpose. They're just not being used right now.)
Input, feedback? Am I barking up the wrong tree? Cheers