PHP xpath() Function

❮ PHP SimpleXML Reference

Example

Run an XPath query on the XML document:

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;

$xml = new SimpleXMLElement($note);

$result = $xml->xpath("/note/to");

print_r($result);
?>
Run Example »

Definition and Usage

The xpath() function runs an XPath query on the XML document.


Syntax

SimpleXMLElement::xpath(path)

Parameter Values

Parameter Description
path Required. Specifies an XPath path to use

Technical Details

Return Value: An array of SimpleXMLElements on success. FALSE on failure
PHP Version: 5.0+

❮ PHP SimpleXML Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.