PHP xpath() Function
Description
The xpath() function runs an XPath query on the XML document.
Syntax
class SimpleXMLElement{
string xpath(path)
}
Parameter
Parameter | Is required | Description |
---|---|---|
path | Required. | What to search for in the XML document |
Return
This function returns an array of SimpleXMLElements on success, and FALSE of failure.
Example
<?xml version="1.0" encoding="ISO-8859-1"?>
<book>//from w w w .java 2 s .c o m
<name>PHP</name>
<name>Java</name>
</book>
PHP Code
<?php// www .j a v a2 s . co m
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("name");
print_r($result);
?>