We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I've been able to follow examples of the loadXML example on this page https://processing.org/reference/XML.html successfully, but I am trying to work with an XML file from wunderground.com weather API that looks like this:
api.wunderground.com/api/5a7d1edd0fd022d0/forecast/q/TN/gatlinburg.xml
Out of this whole thing, I was hoping to just isolate a few elements like HIGH and LOW temperatures and storm warnings. I just can't figure out how to jump to those tags.
Using a different XML from the same API I was able to do what I want with the following code, but the above code has more "Layers".
This is pretty much what I was trying to do:
XML xmlFeed = loadXML("weather.xml");
int numSites = xmlFeed.getChildCount();
//println(numSites);
for (int i = 0; i < numSites; i++) {
XML tag = xmlFeed.getChild(i);
if (tag.getName().equals("temperature_string")) {
String temperature_string = tag.getContent();
println("temperature_string: " + temperature_string);
} else if (tag.getName().equals("dewpoint_f")) {
String dewpoint_f = tag.getContent();
println("dewpoint_f: " + dewpoint_f);
}
}
exit();
I very much appreciate any help anyone is able to give.
Answers
https://forum.Processing.org/two/discussion/10792/access-specific-data-in-a-complex-xml-file
https://forum.Processing.org/two/discussion/14891/loading-in-points-from-xml
Thanks GoToLoop, for all the time you spend helping people. I will try working off the code you referenced when I get home from work tonight and let you know how it goes.
Ok I tried adjusting one of your previous snippets to this:
but now I'm getting a NullPointerException on line 5.
OK! finally figured out how to do what I wanted with the help of GoToLoop and some fiddling. Here's my code to help others (and please let me know if there are better ways to do this):
and this prints:
Thanks again for your help GoToLoop
Very good, congratz! =D> Not better but just slightly diff. below: :)