XPath can be used to filter your results according to any values : xpath « XML « PHP






XPath can be used to filter your results according to any values

 
<?
    $xml = simplexml_load_file('employees.xml');

    $employees = $xml->xpath('/employees/employee[name="Laura Pollard"]');
    foreach($employees as $employee) {
            echo "Found {$employee->name}<br />";
    }
    $employees = $xml->xpath('/employees/employee[age<54]');

    foreach($employees as $employee) {
            echo "Found {$employee->name}<br />";
    }
    $employees = $xml->xpath('//employee[age>=48]');

    foreach($employees as $employee) {
            echo "Found {$employee->name}<br />";
    }
?>
  
  








Related examples in the same category

1.Combine it with an XPath search
2.xpath.php
3.Using XPath and DOM
4.Using XPath and SimpleXML in a basic example
5.Using XPath with DOM in a basic example
6.Using XPath with SimpleXML in a more complicated example
7.XPath DOM Query
8.Searching and Filtering with XPath