thanks PhiLho!
I have added an arrayList to bookNode class to hold author and subject info. But having not used hashmap before yes it does seem abstract so any help would be much appreciated. I am reading through the reference help in processing but so far
I guess the hashmap would be implemented within the bookNode class?
revised code below - if anything is not clear or my code doesn't make sense i will try to clarify.
import proxml.*;
import proxml.XMLElement;
XMLElement branches;
XMLInOut xmlInOut;
bookNode[] bookParticles;
sourceNode[] sourceParticles;
subjNode[] subjParticles;
bookLinks[] bookConnections;
subjLinks[] subjConnections;
/*..................................................................*/
void setup() {
size(300,300);
background(50);
smooth();
//load nodes from file
xmlInOut = new XMLInOut(this);
xmlInOut.loadElement("testData4.xml");
}
/*..................................................................*/
void xmlEvent(XMLElement element){
branches = element;
int nbrNodes = branches.countChildren();
XMLElement node;
XMLElement title;
XMLElement source;
XMLElement subjects;
// parse through branches: gets each row of data in xml file
for(int i = 0; i < branches.countChildren();i++){
//and get the elements of each row
node = branches.getChild(i);
//get the attributes of each element in a row/child - and add attibutes to kin class
/******BOOK DATA******/
title = node.getChild(0);
title.getAttribute("name");
String labelName = title.getAttribute("name");
bookParticles = new bookNode[nbrNodes];
bookParticles[i] = new bookNode(new PVector(random(0,width), random(0,height)));
bookParticles[i].name = labelName;
/******AUTHOR DATA******/
source = node.getChild(1);
source.getAttribute("origin");
String labelOrigin = source.getAttribute("origin");
sourceParticles = new sourceNode[nbrNodes];
sourceParticles[i] = new sourceNode(new PVector(random(0,width), random(0,height)));
sourceParticles[i].name = labelOrigin;
//add author references to arrayList authorSources of bookNode class
bookParticles[i].authorSources.add(source.getAttribute("origin"));
/******SUBJECT DATA******/
subjects = node.getChild(2);
int nbr = subjects.countAttributes();
//add subject references to arrayList subjectTags of bookNode class
bookParticles[i].subjectTags.add(subjects.getAttribute("tag1"));
bookParticles[i].subjectTags.add(subjects.getAttribute("tag2"));
try {
bookParticles[i].subjectTags.add(subjects.getAttribute("tag3"));
}
catch (Exception e) {
}
try {
bookParticles[i].subjectTags.add(subjects.getAttribute("tag4"));
}
catch (Exception e) {
}
try {
bookParticles[i].subjectTags.add(subjects.getAttribute("tag5"));
}
catch (Exception e) {
}
//WHAT TO DO???
//loop through array list to check each value for previous duplicate values
//if exists then ignore it - go to draw links: HOW???
//Or use hashtable: HOW?!?!?!
//subject data is organised as a child with multiple attributes
//loop through attributes of each row/child
for(int j=0; j<nbr; j++){
subjParticles = new subjNode[nbr];
subjParticles[j] = new subjNode(new PVector(random(width), random(height)));
subjParticles[j].display();
//subject to book connections
subjConnections = new subjLinks[nbr];
subjConnections[j] = new subjLinks(subjParticles[j].position.get(), bookParticles[i].position.get());
subjConnections[j].display();
}
//book to author connections
bookConnections = new bookLinks[nbrNodes];
bookConnections[i] = new bookLinks(bookParticles[i].position.get(), sourceParticles[i].position.get());
bookParticles[i].display();
sourceParticles[i].display();
bookConnections[i].display();
}
}
/*..................................................................*/
class bookNode {
PVector position;
String name;
ArrayList authorSources = new ArrayList();
ArrayList subjectTags = new ArrayList();
bookNode(PVector loc) {
position = loc;
}
void display() {
noStroke();
fill(255,0,0);
ellipse(position.x, position.y, 5, 5);
fill(200,200,200,50);
ellipse(position.x, position.y, 15, 15);
// println(authorSources);
// println(subjectTags);
}
}
/*..................................................................*/
class sourceNode { //same as subjNode
PVector position;
String name;
sourceNode(PVector loc) {
position = loc;
}
void display() {
noStroke();
fill(255,255,0);
ellipse(position.x, position.y, 5, 5);
fill(200,200,200,50);
ellipse(position.x, position.y, 15, 15);
}
}
/*..................................................................*/
class bookLinks { //same as subjLinks
PVector bookPos;
PVector sourcePos;
bookLinks(PVector locBook, PVector locSource) {
bookPos = locBook;
sourcePos = locSource;
}
void display() {
stroke(200);
strokeWeight(0.5);
line(bookPos.x,bookPos.y,sourcePos.x,sourcePos.y);
}
}