Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XMLInputFactory factory = XMLInputFactory.newInstance();
- URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
- try {
- InputStream stream = url.openStream();
- XMLStreamReader reader = factory.createXMLStreamReader(stream);
- while(reader.hasNext()) {
- int event = reader.next();
- switch (event) {
- case XMLStreamConstants.START_ELEMENT:
- String attributeValue = reader.getAttributeValue(0);
- String attributeValue2 = reader.getAttributeValue(1);
- String attributeName = reader.getAttributeLocalName(0);
- if("time".equals(attributeName)) {
- time = attributeValue;
- currencies.add(new Currency("EUR", (double) 1, time)); // Puts the "base" in there as well
- }
- if("currency".equals(attributeName))
- currencies.add(new Currency(attributeValue, Double.parseDouble(attributeValue2), time));
- break;
- case XMLStreamConstants.CHARACTERS:
- if (!reader.isWhiteSpace()) {
- String contents = reader.getText().trim();
- }
- break;
- }
- }
- this.writeToFile();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement