How to use xpath in PHP

In this article I will explain how xpath function used in PHP.
  • 1556

xpath() Function

This function runs XPath query on the XML file.

Syntax

class SimpleXMLElement
{
string xpath(path)
}

Example

XML File

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Rock</to>
<from>Sachin</from>
<heading>Reminder</heading>
<body>I Love India</body>
</note>

PHP Code

<html>
<body>
<?php
$xml = simplexml_load_file("parse.xml");
$result = $xml->xpath("from");
print_r($result);
?>
</body>
</html>

 

Output


xpath-php.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.