Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. XMLInputFactory factory = XMLInputFactory.newInstance();
  2.         URL url = new URL("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
  3.        
  4.         try {
  5.             InputStream stream = url.openStream();
  6.             XMLStreamReader reader = factory.createXMLStreamReader(stream);
  7.        
  8.             while(reader.hasNext()) {
  9.                 int event = reader.next();
  10.                 switch (event) {
  11.                     case XMLStreamConstants.START_ELEMENT:
  12.                         String attributeValue = reader.getAttributeValue(0);
  13.                         String attributeValue2 = reader.getAttributeValue(1);
  14.                         String attributeName = reader.getAttributeLocalName(0);
  15.  
  16.                         if("time".equals(attributeName)) {
  17.                             time = attributeValue;
  18.                             currencies.add(new Currency("EUR", (double) 1, time)); // Puts the "base" in there as well
  19.                         }
  20.  
  21.                         if("currency".equals(attributeName))
  22.                             currencies.add(new Currency(attributeValue, Double.parseDouble(attributeValue2), time));
  23.                     break;
  24.                     case XMLStreamConstants.CHARACTERS:
  25.                         if (!reader.isWhiteSpace()) {
  26.                             String contents = reader.getText().trim();
  27.                         }
  28.                     break;
  29.                 }
  30.             }
  31.      
  32.             this.writeToFile();
  33.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement