We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys,
I am fairly new to this external-data-into-Processing stuff, so I am wondering what I am doing wrong with this tiny piece of code ...
XML root = loadXML("http://www.w3schools.com/xml/cd_catalog.xml");
XML[] year = root.getChildren("CATALOG/CD/YEAR");
for (int i = 0; i < year.length; i++) {
println(year[i]);
}
Thanks in advance!
Answers
What does this code do? Does it throw an exception? Behave strangely? Something else?
Why are you passing an entire a tag into the loadXML() method? It just expects the URL, not the entire tag. Also, you either have to escape inner quotation marks, or use single quotes instead.
Hey KevinWorkman -
Thanks for the quick reply.
It should - at least that's what I am trying to do - be able to print the each of the years represented in the cd_catalog.xml-file.
But the problem is that it doesn't do anything ... It doesn't println(year) of each of the catalogued CD's in the text/message area?
Thanks.
Sorry about that - I misunderstood your question ... I haven't passed an entire tag into the loadXML() method. I am unsure why it shows up like that in the code, as I have only placed the following in the loadXML() method:
XML root = loadXML("http://www.w3schools.com/xml/cd_catalog.xml");
Can you do some debugging? Try printing out the value of root.toString(). What does that show you?
You must omit the root from your XQuery:
XML[] years = root.getChildren("CD/YEAR");