$xml = <<John 30 XML; $sxe = new SimpleXMLElement($xml); $result = $sxe->xpath('/root/person[name="Jane"]/age'); echo $result[0]; Jane 25
$xml = <<In this example, the code creates an XML document that represents a list of people, each with an age and gender attribute. Then, it uses xpath to filter the list to only include people who are male, and outputs their ages to the screen. Package Library: SimpleXML SimpleXMLElement xpath is part of the SimpleXML package/library, a built-in PHP extension that provides an easy way to access and manipulate XML documents. It provides a simple and convenient object-oriented interface to the underlying XML document, making it easier to parse and extract data from XML files.XML; $sxe = new SimpleXMLElement($xml); $result = $sxe->xpath('/root/person[@gender="male"]'); foreach ($result as $person) { echo $person['age'] . "\n"; }