Searching elements using XPath
XPath or the XML Path is used to navigate an XML document. It is basically a query language that provides a standard set of expressions and functions for traversing a document tree. XPath operates on a document tree and can be used for functions, such as searching, comparing, and so on in a document.
PHP has built-in support for using XPath. This recipe will explain some concepts of XPath and how they can be used to get information from XML.
Using the common.xml
file we will write a simple example that will demonstrate the capabilities of XPath.
Getting ready
Like earlier recipes, create a separate folder named Recipe3
inside the Chapter3
directory.
How to do it...
Create an HTML file and name it as
index.html
. Create four buttons that will be used to show different usage of XPath. Also, create an empty DIV element for displaying the result. Also, define some CSS in the<head>
section for better display.<html> <head> <title>Using XPath...