I am trying to parse this java XML http://www.bnr.ro/nbrfxrates.xml and i want to extract the rate of the chosen curency, this is what I have done so far and it is not working... Can you tell me what the the right way to get to the currency rate and print it out inside the switch? ps: the xml is loaded using:
public static void main(String[] args) throws SAXException, IOException {
URL oracle = new URL("http://www.bnr.ro/nbrfxrates.xml");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
Scanner keyboard = new Scanner(System.in);
System.out.println("What currency rate do you need?");
String myString;
myString = keyboard.nextLine();
System.out.println("myint: " + myString);
String ales = myString;
switch(ales ){
case "USD":
final Pattern pattern = Pattern.compile("<Rate>(.+?)</Rate>");
final Matcher matcher = pattern.matcher("<Rate></Rate>");
matcher.find();
System.out.println(matcher.group(1));
break;
default:
System.out.println("We don't know");