How to parse a specific line from xml/rss feed
in
Programming Questions
•
4 months ago
Hello everyone
I've been trying to make a program that makes several LED's turn on and off depending on xml feed's data. Unfortunately i am very new to Processing and i have like a week to finish this project, but problems keep occuring everywhere as usual :) . Anyway to the point so far one of the main problems is that half of the things I am trying to do(such as turn LED on and off) works on Processing version 1.5 and part of my xml parsing code works on version 2+. Currently I am trying to run this code in order to get the xml info I want :
The code:
/**
* 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
*/
// Array to store titles
String[] titles;
XML xml;
XML[] children;
PFont font;
void setup() {
size(700, 300);
background(0);
noStroke();
// Setup font
font = loadFont("Calibri-12.vlw");
textFont(font, 12);
xml = loadXML("http://weather.yahooapis.com/forecastrss?w=27764362");
children = xml.getChildren("channel/yweather:wind"); // the program reads the xml content without yweather:wind, but i need exactly this bit, so thats why i left it so you can see that I've tried
titles = new String[children.length];
for (int i = 0; i < children.length; i++) {
String title = children[i].getContent();
titles[i] = title;
}
}
void draw() {
background(255);
// Draw all titles with bars and colors depending on its length
for (int i = 0; i < titles.length; i++) {
float y = (i+1) * 15;
fill(255 - constrain(titles[i].length(), 0, 255));
rect(8, y - 11, 14, 14);
fill(127, 100);
rect(23, y - 11, titles[i].length() * 2, 14);
fill(0, 220);
text(titles[i], 26, y);
}
}
So basically what I need to do is get the "yweather:wind" line of the XML code which it doesn show and get wind speed and wind direction attributes and use those values later in order to control the LED's . I've tried all possible getChild commands such as (channel/yweather:wind, channel/yweather: and etc) Unfortunately this seems to be harder than i expected considering all the version incompatibility. I've connected everything through Arduino I also tried using Firmata library which works only in ver 1.5 sort of :D
PS: as you can probably see one part of the code doesnt do anything specific for xml reading it just colors the text, but this is an example which Im using and if i delete this bit of the code i just get a black screen.
I would appreciate any help since this is my final project and the time is passing by quickly
Thanks
Nick
1