The xpath() function runs an XPath query on the XML document.
class SimpleXMLElement{
string xpath(path)
}
Parameter | Is required | Description |
---|---|---|
path | Required. | What to search for in the XML document |
This function returns an array of SimpleXMLElements on success, and FALSE of failure.
<?xml version="1.0" encoding="ISO-8859-1"?> <book> <name>PHP</name> <name>Java</name> </book>
PHP Code
<?php
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("name");
print_r($result);
?>