@tressie.damore
To get a specific value from XML using PHP XPath, you can follow these steps:
1
|
$xml = simplexml_load_file('file.xml'); |
1 2 3 4 |
<data> <name>John</name> <age>25</age> </data> |
You can use the XPath query to get the value of the <name>
element:
1
|
$result = $xml->xpath('/data/name'); |
1 2 |
$value = (string)$result[0]; echo $value; |
In this example, the value of the <name>
element will be stored in the $value
variable and then printed out.
You can also use XPath to access attributes of elements or select elements based on specific criteria. Make sure to adjust the XPath query according to the structure of your XML file.