Rss Feeds: Parsing Numerical Data
in
Programming Questions
•
9 months ago
I'm working with an edit of
"Till Nagel's SimpleFeedVisualizer" trying to gather numerical data from
:
http://www.newyorkfed.org/xml/data/ff/ffd.xml <base: OBS_VALUE> XMLElement. Unfortunately I have some poor understanding of the code. I'm trying to gather numerical data from a string a variable so e.g.
String s; and parse
int values into a variable e.g.
int I = Integer.parseInt(s); I'm not clear on the where I should be declaring these statements, and if at there's is any need to edit the section loading RSS Feeds.
- /**
- * Loads RSS feed and visualizes the titles in a very simple manner.
- * Color and bar depend on the length of the corresponding title.
- *
- * (c) 2008 Till Nagel, btk.tillnagel.com
- */
- //import processing.xml.*;
- // Array to store titles
- String[] titles;
- PFont font;
- void setup() {
- size(700, 300);
- background(0);
- noStroke();
- // Setup font
- font = loadFont("Calibri-12.vlw");
- textFont(font, 12);
- // Load RSS feed
- String url = "http://www.newyorkfed.org/xml/data/ff/ffd.xml";
- XMLElement rss = new XMLElement(this, url);
- // Get data of each element
- XMLElement[] dataXMLElements = rss.getChildren("ff: Obs/base: OBS_VALUE");
- numbers = new String[dataXMLElements.length];
- for (int i = 0; i < dataXMLElements.length; i++) {
- String s = dataXMLElements[i].getContent();
- int I = Integer.parseInt(s);
- // Store data in array for later use
- numbers[i] = data;
- }
- }
- void draw() {
- background(255);
- // Draw all titles with bars and colors depending on its length
- for (int i = 0; i < numbers.length; i++) {
- float y = (i+1) * 15;
- fill(255 - constrain(numbers[i].length(), 0, 255));
- rect(8, y - 11, 14, 14);
- fill(127, 100);
- rect(23, y - 11, numbers[i].length() * 2, 14);
- fill(0, 220);
- text(numbers[i], 26, y);
- }
- }
1