hi again,
this problem of recognising duplicate values is driving me nuts - sorry if i'm being a numpte! a bit tentative about posting about this problem again.
i have updated the code i posted before below. And it seems to work properly in terms of bringing the data in (same as i posted) and parsing it correctly. Each branch is represented as a red rectangle - of which there are two. And each attribute is represented with a dot, coloured to which type of data it is. So i think the code its right:Cool. But i can't get my head around how to check if data being brought in is a duplicate of other data
from playing with the code it seems there is a number of different ways to "collect" the data and then represent it;
for example node.getAttribute("title"); gathers a particular attribute - so i could check for duplicates here
and (commented out below) an array which gathers all attributes which could then be checked - guess making this an arraylist would be easier/better but my brain became spaghetti trying!
this is only the start of what i am hoping to do in terms of representing the data - once i can get it in recognising duplicate data, so i will have other questions for sure but any help on how to find values of a list or arraylist which equals another value in the same array/arraylist would be very much appreciated.
/////////////////////code//////////////////////////
//loads data from an xml file
//represents each row of data in file graphically as a red rectangle
//and data in each row as a dot coloured relative to type of data
//feb 2010
import proxml.*;
import proxml.XMLElement;
XMLElement branches;
XMLInOut xmlInOut;
/*..................................................................*/
void setup() {
size(200,200);
background(0);
smooth();
//load nodes from file
xmlInOut = new XMLInOut(this);
xmlInOut.loadElement("testData3.xml");
}
/*..................................................................*/
void xmlEvent(XMLElement element){
branches = element;
XMLElement node;
// parse through branches: gets each row of data in xml file
for(int i = 0; i < branches.countChildren();i++){
node = branches.getChild(i);
//print(node);
//draw a node for each child
fill(255,0,0);
rect(random(width), random(height), 10, 10);
//gets values of particular attributes
node.getAttribute("title");
print(node.getAttribute("title") + ", ");
fill(255,255,0);
ellipse(random(width), random(height), 10, 10);
node.getAttribute("source");
print(node.getAttribute("source") + ", ");
fill(255,0,255);
ellipse(random(width), random(height), 10, 10);
node.getAttribute("tag1");
print(node.getAttribute("tag1") + ", ");
fill(50,50,255);
ellipse(random(width), random(height), 10, 10);
// ArrayList v = new ArrayList();
// v.add(node.getAttribute("tag1"));
// for(int j=0; j<v.size(); j++)
// **knowing duplicate data is here** is this the place to check - loop through each item of arraylist v checking it against other items in the same list to see if equal?
try {
node.getAttribute("tag2");
print(node.getAttribute("tag2") + ", ");
fill(50,150,255);
ellipse(random(width), random(height), 10, 10);
}
catch (Exception e) {
}
try {
node.getAttribute("tag3");
println(node.getAttribute("tag3") + ", ");
fill(50,255,255);
ellipse(random(width), random(height), 10, 10);
}
catch (Exception e) {
}
// String attributes [] = node.getAttributes();
// attributes = reverse(attributes);
// println(attributes);
// // parse through attributes of each branch: gets data in the row
// for(int j = 0; j < attributes.length; j++){
// print(attributes[j]+":" + node.getAttribute(attributes[j]) + ", ");
// fill(255);
// ellipse(random(width), random(height), 10, 10);
// }
}
}