import java.io.InputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class Running {
public static void main(String[] args) {
try {
SimpleDateFormat ff = new SimpleDateFormat("dd.MM.yyyy");
URL url = new URL("http://cbar.az/currencies/" + ff.format(new Date()) + ".xml");
InputStream inputStream = url.openConnection().getInputStream();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(inputStream);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("Valute");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
if (eElement.getAttribute("Code").equals("USD")) {
System.out.println(eElement.getElementsByTagName("Name").item(0).getTextContent() + " : " + eElement.getElementsByTagName("Value").item(0).getTextContent());
}
if (eElement.getAttribute("Code").equals("EUR")) {
System.out.println(eElement.getElementsByTagName("Name").item(0).getTextContent() + " : " + eElement.getElementsByTagName("Value").item(0).getTextContent());
}
if (eElement.getAttribute("Code").equals("RUB")) {
System.out.println(eElement.getElementsByTagName("Name").item(0).getTextContent() + " : " + eElement.getElementsByTagName("Value").item(0).getTextContent());
}
if (eElement.getAttribute("Code").equals("XAU")) {
System.out.println(eElement.getElementsByTagName("Name").item(0).getTextContent() + " : " + eElement.getElementsByTagName("Value").item(0).getTextContent());
}
if (eElement.getAttribute("Code").equals("TRY")) {
System.out.println(eElement.getElementsByTagName("Name").item(0).getTextContent() + " : " + eElement.getElementsByTagName("Value").item(0).getTextContent());
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}