We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › proxml: ignoring equal attribute values
Page Index Toggle Pages: 1
proxml: ignoring equal attribute values (Read 737 times)
proxml: ignoring equal attribute values
Feb 17th, 2010, 3:07am
 
Hi,

using proxml i am importing data which i want to represent as a noded-tree structure/graph.

the code below works to import info and to draw each attribute as a node/ellipse but now i want to check if an attribute already exists and if it does to NOT draw it again.

duplicates will only appear between different children. for example my data is about book data, for which each book is a child, with attributes (title, author, subject1, subject2, subject3). So possible duplicates could be author or subject1, 2, 3.

can anyone help please. thanks.

Code:
//draws an ellipse for each attribute of branch

import proxml.*;
import proxml.XMLElement;

XMLElement branches;
XMLInOut xmlInOut;
/*..................................................................*/
void setup() {
 size(200,200);
 background(0);
 smooth();

 //load file
 xmlInOut = new XMLInOut(this);
 xmlInOut.loadElement("testData3.xml");
}
/*..................................................................*/
void xmlEvent(XMLElement element){
 branches = element;
 XMLElement node;
 
 // parse through branches
 for(int i = 0; i < branches.countChildren();i++){
   node = branches.getChild(i);
   String[] attributes = node.getAttributes();
   // parse through branches to create nodes for each attribute
   for(int j = 0; j < attributes.length; j++){
     
     //draw a node for each attribute
     ellipse(random(width), random(height), 10, 10);
   }
 }
}
Re: proxml: ignoring equal attribute values
Reply #1 - Feb 17th, 2010, 3:48am
 
You must store the data you are parsing, then on each new data, look in past data to see if it is already there. If so, just discard it.
Re: proxml: ignoring equal attribute values
Reply #2 - Feb 17th, 2010, 7:23am
 
Hi PhiLho and thanks for the response.

yes, i figured that - sorry if my post was not clear. The problem i am struggling with is how to code this-or to start to!

Would you have any idea how i could start or go about this please?

my thoughts, in some kind of pseudo code, are;
- load first child attributes into an array
- draw those elements as a node
- load next child attributes into a second array
- check both arrays for duplicates
- remove duplicates from 2nd array
- draw those elements remaining in second array
- and add them to 1st array
- keep doing this until end

of course could just do the sorting and draw all at end but quite liked idea of staging.

Thanks for any help.
Re: proxml: ignoring equal attribute values
Reply #3 - Feb 17th, 2010, 7:43am
 
Can you show a small significant chunk of your data, including parts showing the duplication problem?
Re: proxml: ignoring equal attribute values
Reply #4 - Feb 17th, 2010, 7:55am
 
this is the data from the xml file i am using.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<branches>
     <node title="book1" source="author1" tag1="topic1" tag2="topic2" tag3="topic3"/>
     <node title="book2" source="author2" tag1="topic1"/>
</branches>
Re: proxml: ignoring equal attribute values
Reply #5 - Feb 19th, 2010, 5:43am
 
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 Cry

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);
//        }

 }
}
Page Index Toggle Pages: 1