XMLElement Test4 getChildren(): getChildren(), getName()

Source

// The following short XML file called "sites.xml" is parsed 
// in the code below. It must be in the project's "data" directory
//<?xml version="1.0"?> 
// <menu> 
//  <breakfast-menu>
//    <food>
//      <name id="0"> Belgian Waffles</name> 
//      <price id="1"> $5.95</price>
//      <description id="2"> two of our famous Belgian Waffles with plenty of real maple syrup</description> 
//      <calories id="3"> 650</calories>
//    </food> 
//      <food>
//      <name id="0"> Strawberry Belgian Waffles</name> 
//      <price id="1"> $7.95</price>
//      <description id="2"> light Belgian waffles covered with strawberrys and whipped cream</description> 
//      <calories id="3"> 900</calories>
//    </food> 
//  </breakfast-menu> 
// </menu> 

XMLElement xml;

void setup() {
  size(200, 200);
  xml = new XMLElement(this, "menu.xml");
  XMLElement[] kids = xml.getChildren("breakfast-menu/food");
  for (int i=0; i < kids.length; i++) {
    String site = kids[i].getName();
    println(site); //prints food food
  }
}