It is to count the number of times - so in an array
Code:
Object [] records
that contains all of my XML records which, when printed to the screen look like this:
Code:
<RECORD><chapter>Bauhaus to Desktop</chapter><title>Bahaus I</title><example>Nice picture</example></RECORD>
<RECORD><chapter>Meta-Media</chapter><title>meta-data</title><example>Elements in Meta-Data</example></RECORD>
<RECORD><chapter>Representing IT Society</chapter><title>Computation</title><example>Casey Reas</example></RECORD>
...
What I want to do is count the number of instances that a phrase, such as "Representing IT Society", appears. I thought that I can implement some sort of counter that would do the trick.
Later in the code, the content (what is inside each <RECORD> tag is parsed to a String array..The code looks like this:
Code:
for (int i=0; i< records.length; i++)
{
//println(records.length);
// Determines the x-coordinate of where an individual chapter begins based on the Nucleus' x-position + sin*numeric radian value
kidx=centerNucleus.nx+radius*sin(radians(angle)*i);
// Determines the y-coordinate of where an individual chapter begins based on the Nucleus' y-position + cos*numeric radian value
kidy=centerNucleus.ny+radius*cos(radians(angle)*i);
// If the nucleus has been clicked, then the chapter nodes, lines, and section lines and nodes get redrawn based on the x,y coordinates
// of the mouse. Otherwise, nothing besides the center nucleus will be drawn on the screen
Object[] rec_info = ((XMLElement)records[i]).getChildren().toArray();
if (nucleusclicked == true)
{
if (i <= 13)
{
stroke(255); // Sets color of line from Nucleus to Chapter (0 = black, 255 = white)
line(centerNucleus.nx, centerNucleus.ny, kidx, kidy); // Draws a line from the Nucleus' position to where the node for chapter[i] will be created
noFill(); // Fill color for chapter node
chapterNode[i].drawChapter(kidx,kidy,noderadius); // Draws the actual chapter node
}
for( int r=0; r<rec_info.length; r++)
{
if( r == 0)
{
for( int s=0; s<1; s++)
{
//println( ((XMLElement)rec_info[r]).getContent());
String c = ((XMLElement)rec_info[r]).getContent().toString();
String[] d = new String[records.length];
d[i] = c;
//println( ((XMLElement)rec_info[r]).getContent());
if( ((XMLElement)rec_info[r]).getName().equals("chapter"))
{
fill(123,30,134);
if( (i > 13) )
{
// print nothing
} else {
text(d[i],kidx,kidy-noderadius);
}
}
//println( ((XMLElement)rec_info[r]).getContent());
//println(chaptertext[i]); // Prints the name of each individual chapter
//fill(255); // Chapter text COLOR
//text(chaptertext[i], kidx,kidy-noderadius); // Writes the text from the chaptertext array where that individual chapter is positioned
//noFill(); // Section node COLOR
//chapters[i].drawkids(kidx,kidy,radius/2); //Draws SECTION lines and NODES for each CHAPTER
//println(d[i]);
}
}
}
}
}
So that it iterates (at the moment) through only the <CHAPTER> tags to retrieve the content.