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 & HelpPrograms › strange behaviour with node.getAttribute("")
Page Index Toggle Pages: 1
strange behaviour with node.getAttribute("") (Read 1391 times)
strange behaviour with node.getAttribute("")
May 16th, 2005, 3:09pm
 
hi all,

i'm trying to loop through some XML, and stop when certain attributes are found to be true. i'm using the following code:

 for(int i=0; i<objNodes.length; i++) {
   XMLElement node=(XMLElement)objNodes[i];

   if(node.getAttribute("label") != "connection") {
     println("im in the IF");
     lTeams[i] = node.getAttribute("label");
     
     }

i never seem to get inside my IF statement, and i've done a println on node.getAttribute("label"), which shows up the string "connection" just fine.

i've also had trouble using text() to display node.getAttribute("label") as in:

text(node.getAttribute("label"), 0,0);

all i get is the following error:

'Perhaps you wanted the overloaded version "void text(char$1, float$2, float$3") instead?'

thanks for your help, i'm just starting out - i hope it's not too stupid a question :\

cheers, nick
Re: strange behaviour with node.getAttribute("")
Reply #1 - May 16th, 2005, 3:20pm
 
two problems: (1) string comparison and (2) i think XMLElement.getAttribute returns an Object not a String.

(1) see here:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1116168495;start=0
http://processing.org/faq/bugs.html#issues

(2) try:
text( (String)node.getAttribute("label"), 0,0 );

F
Page Index Toggle Pages: 1