I'm still very new to processing. I'm having some trouble working with XML.
I have the following XML:
Code:<recenttracks user="RJ" page="1" perPage="10" totalPages="3019">
<track>
<artist>Aretha Franklin</artist>
<name>Sisters Are Doing It For Themselves</name>
<date uts="1213031819">9 Jun 2008, 17:16</date>
</track>
<track>
<artist>Radiohead</artist>
<name>Karma Police</name>
<date uts="1213031819">9 Jun 2008, 17:13</date>
</track>
</recenttracks>
I want to loop through each <track>, displaying the <artist> and other children.
My issue is very simple, I think.. I'm running into a problem with getChildren. Below is my code:
Code:xml = new XMLElement(this,"data.xml");
XMLElement tracks = xml.getChildren();
for (int i = 0; i < numTracks; i++) {
XMLElement track = tracks.getChild(i);
XMLElement artist = track.getChild("track/artist");
String artistName = artist.getContent();
println("1: " + artistName);
}
this is my attempt to dig one level into my XML so that I'm working with just <track> elements instead of <recenttracks>. The error I get: "cannot convert from XMLElement[] to XMLElement". What I understand is that it's trying to convert from an object to an array. However, when I try this instead, I get another error:
XMLElement[] tracks = xml.getChildren();
The error is "cannot invoke getChild(int) on the array type XMlElement[]"
So I'm not sure where to go from here, but I'm sure there's a better way.
Any help would be greatly appreciated, let me know if you need any more information!