Securing Higher Grades Costing Your Pocket? Book Your Assignment at The Lowest Price Now!


What is XPATH in XML? - Examples & Functions

Introduction to XPath

We can define XPath is a language that determine a way to locate and process items in XML stands for extensible markup language which is accessed by using an addressing syntax whose path based on document's logical structure or hierarchy. XPath is a syntax that is used to define the parts of an XML document and use path expression to navigate in the document. It is a W3C recommendation. This is one of the major element of XSLT and also used in Xquery, Xpointer and Xlink. It allows programmers to deal with the document at a higher level of abstraction and abstract information that defined in XML information set.

Function of XPath

Imagine a city with many restaurants. Each will have different speciality and also can have different location, stars, year when the established. So all the information stored in the computer of the restaurant reviews, but when we search for the restaurant the data transfer from the resturant's reviews in our computer is through an XML file. So an XML file looks like

<?xml version='1.0'?>
<name>Le meridian</name>
<speciality>Chinese Noodles</speciality>
<location>Central Delhi</location>
<price>$75 for two person</price>
<star>5 star</star>

In code first line denotes the XML version which is looks like a file cabinet. Name of the cabinet is restaurants and inside it there are different information like category, name, type, speciality, location, prices and so on. So restaurants is the root element or we can say root node and the information with the specify name is known as a node which is denoted by the opening and closing tags. So in the above XML file root node is restaurants and the other nodes are category, name, type, speciality, location, prices and so on. There is a method to secure the XML file is that write code for the file in any preferred language like C++, java and so on.

Using Xpath to get data from XML Files

Now we are going to show you sample example of the above XML file:

<?xml version='1.0' encoding='UTF-8'?>
<name>The One - Le Meridien</name>
<type>Stone oven Pizza</type> 
<location>Central Delhi</location>
<price>$75 for two person</price>
<star>5 star</star>
<name>Moti mahal</name>
<speciality>Tandoori Chicken</speciality>
<location>Darya Ganj</location>
<price>2000 for two person</price>
<star>4 star</star>
<category='Fast Food'>
<speciality>Kennedy's Pies</speciality>
<location>west patel nagar</location>
<price> 1000 for two person</price>
<star>4 star</star>
Assignment Help Features
Assignment Help Services
  • Assignment Help
  • Homework Help
  • Writing Help
  • Academic Writing Assistance
  • Editing Services
  • Plagiarism Checker Online
  • Proofreading
  • Research Writing Help
QR Code Assignment Help