Below are a few xml examples using xpath:

Displaying the xml file at "http://alexchang.me/cs75/example.xml":
  

xpath('//student') will return all student elements:
xpath('/school//student'); ?>
  

Example 0: Using foreach: foreach($xml->students->student as $student):

students->student as $student) { echo "Student " . $student->name . " has an ID # of " . $student["id"] . "
"; } ?>
Example 1: Getting every student with undergrad as their : $xml->xpath('//student[status="undergrad"]');"
xpath('//student[status="undergrad"]'); ?>

foreach($results1 as $results1)
{
echo $results1->name;
}

The above gets me:
name; echo "
"; } ?>
Example 2: Comparing value of an element: $xml->xpath('//student[gpa>3.0]'); xpath('//student[gpa>3.0]'); ?>


Example 3: Using the @ attribute to get all students in class of 2010:
xpath('//student[@class = "2010"]'); ?> xpath('//student[@class = "2010"]'); ?>


Example 4: Using $variables as part of the xpath:

$PATH='student[gpa>3.0]';
$results4 = $xml->xpath("//students/$PATH");
$results4 =
3.0]'; $results4 = $xml->xpath("//students/$PATH"); ?>