Now, leaving our main() method, we'll define our new PrintCars() method. I have divided the definition of the PrintCars() function into eight parts:
- Because we're in the entry class of our program and the PrintCars() method is being called by the static main() method, it should probably be a static function. All it's going to do is print to our console, so void is an appropriate return type. We already know it's going to take NodeList of cars as input:
public static void PrintCars(NodeList cars)
{
}
- Once we've entered this function, we know we have a list of car XML elements at our disposal. But in order to print each one out, we're going to have to loop through them. We've already looped through XML NodeList ...