Why won't my if satements work with my XML data?

Everytime I try to run the following, it tells me "_Answer" not recognised. Please help me.

XML lynnsXmlfile;
float x = 10;
int y= 0;

//int ySpace = 20;


void setup(){
  size(800,600);
  background(255);
  smooth();


  lynnsXmlfile = loadXML("surveys.xml");
  //println(lynnsXmlfile);

  float placement = width*5;
  float MaleX = placement;
  float MaleY = 300;
  float FemX = placement*20;
  float FemY = 300;
  float North_JohannesburgX = placement*30;
  float North_JohannesburgY = 300;
  float West_JohannesburgX = placement*40;
  float West_JohannesburgY = 300;
  float East_JohannesburgX = placement*50;
  float East_JohannesburgY = 300;
  float South_JohannesburgX = placement*60;
  float South_JohannesburgY = 300;
  float WhiteX = placement*70;
  float WhiteY = 300;
  float BlackX = placement*80;
  float BlackY = 300;
  float IndianX = placement*90;
  float IndianY = 300;





    XML [] surveys = lynnsXmlfile.getChildren("record");
    XML [] genderQuestions = lynnsXmlfile.getChildren("record/gender");
    XML [] raceQuestions = lynnsXmlfile.getChildren("record/race");
    XML [] locationQuestions = lynnsXmlfile.getChildren("record/location");
    XML [] area_ratingQuestions = lynnsXmlfile.getChildren("record/area_rating");
    XML [] frequency_eatQuestions = lynnsXmlfile.getChildren("record/frequency_eat");
    XML [] frequency_mealsQuestions = lynnsXmlfile.getChildren("record/frequency_meals");
    XML [] frequency_mostQuestions = lynnsXmlfile.getChildren("record/frequency_most");
    XML [] frequency_bestQuestions = lynnsXmlfile.getChildren("record/frequency_best");
  //XML [] survey = lynnsXmlfile.getContent("data-set/location");


  //printArray(surveys);

  for(int i=0; i<=surveys.length-1; i++){
  String genderAnswer = genderQuestions[i].getContent();
  println("gender "+i+": "+genderAnswer);
  String raceAnswer = raceQuestions[i].getContent();
 println("race "+i+": "+raceAnswer);
  String locationAnswer = locationQuestions[i].getContent();
  //println("location "+i+": "+locationAnswer);
  String frequency_eatAnswer = frequency_eatQuestions[i].getContent();
  //println("frequency eat "+i+": "+frequency_eatAnswer);
 String frequency_mealsAnswer = frequency_mealsQuestions[i].getContent();
 String frequency_mostAnswer = frequency_mostQuestions[i].getContent();
 String frequency_bestAnswer = frequency_bestQuestions[i].getContent();
 String area_ratingAnswer = area_ratingQuestions[i].getContent();
  }



   fill(100,255,255);
   //println(genderX);
   ellipse(MaleX, MaleY, 40,40);
   ellipse(FemX, FemY, 40,40);
   ellipse(North_JohannesburgX, North_JohannesburgY, 40,40);
   ellipse(West_JohannesburgX, West_JohannesburgY, 40,40);
   ellipse(East_JohannesburgX, East_JohannesburgY, 40,40);
   ellipse(South_JohannesburgX, South_JohannesburgY, 40,40);
   ellipse(WhiteX, WhiteY, 40,40);
   ellipse(BlackX, BlackY, 40,40);
   ellipse(IndianX, IndianY, 40,40);


   if (genderAnswer.indexOf("Fem") != -1){
    fill(125,255,255); 
     noStroke();
   }

      if (genderAnswer.indexOf("Male") != -1){
    fill(255,255,125); 
     noStroke();
   }

    if (locationAnswer.indexOf("North_Johannesburg") != -1){
    fill(125,255,255); 
     noStroke();
   }else{
     fill(255,255,125); 
     noStroke();
   }

    if (raceAnswer.indexOf("White") != -1){
    fill(250,255,250);
     noStroke();
   }else{
     fill(255,255,215);
     noStroke();
   }


    if (frequency_bestAnswer.indexOf("North_Johannesburg") != -1){
    fill(125,0,0); 
     noStroke();
   }else{
     fill(5,5,125); 
     noStroke();
   }




    fill(30);
   noStroke();
   rect(0,500,800,100);
}

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <record>
        <gender>Male</gender>
        <race>Indian</race>
        <location>South_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Non-binary</gender>
        <race>White</race>
        <location>East_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>East_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>5</rating>
        <eat>Three or four</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>Three or four</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>1</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>One or more</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>One or more</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>1</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>5</rating>
        <eat>One or two</eat>
        <meals>Breakfast</meals>
        <most>East_Johannesburg</most>
        <best>East_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>West_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Breakfast</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>West_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>South_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>One or more</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Breakfast</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>5</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>Pretoria east</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>West_Johannesburg</location>
        <rating>3</rating>
        <eat>Three or four</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>One or more</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>East_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Lunch</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>West_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>Three or four</eat>
        <meals>One or more</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>West_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Male</gender>
        <race>White</race>
        <location>Centurion</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>One or more</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>3</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>North_Johannesburg</location>
        <rating>4</rating>
        <eat>One or two</eat>
        <meals>Dinner</meals>
        <most>North_Johannesburg</most>
        <best>North_Johannesburg</best>
    </record>
    <record>
        <gender>Fem</gender>
        <race>White</race>
        <location>West_Johannesburg</location>
        <rating>5</rating>
        <eat>One or two</eat>
        <meals>One or more</meals>
        <most>West_Johannesburg</most>
        <best>West_Johannesburg</best>
    </record>
</data-set>

Answers

  • What line is throwing the error? When loading the file or what line number? Can you make your xml data available?

    Kf

  • Please don't post the same question multiple times. It confused people and splits the answers.

    I have deleted the other one.

Sign In or Register to comment.