পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Tuesday, January 17, 2017

Java XPath Parser - Overview

The XPath is an official recommendation of the World Wide Web Consortium (W3C). It defines a language to find information in an XML file. It is used to traverse elements and attributes of an XML document. XPath provides various type of expressions which can be used to enquire relevant information from the XML document.

What is XPath?

  • Structure Definations - XPath defines the parts of an XML document like element, attribute, text, namespace, processing-instruction, comment, and document nodes
  • Path Expressions XPath provides powerful path expressions select nodes or list of nodes in XML documents.
  • Standard FunctionsXPath provides a rich library of standard functions for manipulation of string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values etc.
  • Major part of XSLTXPath is one of the major element in XSLT standard and is must have knowledge in order to work with XSLT documents.
  • W3C recommendationXPath is official recommendation of World Wide Web Consortium (W3C).
Here is the input text file we need to parse:
<?xml version="1.0"?>
<class>
   <student rollno="393">
      <firstname>dinkar</firstname>
      <lastname>kad</lastname>
      <nickname>dinkar</nickname>
      <marks>85</marks>
   </student>
   <student rollno="493">
      <firstname>Vaneet</firstname>
      <lastname>Gupta</lastname>
      <nickname>vinni</nickname>
      <marks>95</marks>
   </student>
   <student rollno="593">
      <firstname>jasvir</firstname>
      <lastname>singn</lastname>
      <nickname>jazz</nickname>
      <marks>90</marks>
   </student>
</class>

XPath Expressions

XPath uses a path expression to select node or list of nodes from an xml document. Following is the list of useful paths and expression to select any node/ list of nodes from an xml document.
ExpressionDescription
node-nameSelect all nodes with the given name "nodename"
/Selection starts from the root node
//Selection starts from the current node that match the selection
.Selects the current node
..Selects the parent of the current node
@Selects attributes
studentExample: Selects all nodes with the name "student"
class/studentExample: Selects all student elements that are children of class
//studentSelects all student elements no matter where they are in the document

Predicates

Predicate are used to find specifi node or a node containing specific value and are defined using [...] .
ExpressionResult
/class/student[1]Selects the first student element that is the child of the class element.
/class/student[last()]Selects the last student element that is the child of the class element.
/class/student[last()-1]Selects the last but one student element that is the child of the class element.
//student[@rollno='493']Selects all the student elements that have an attribute named rollno with a value of '493'

No comments:

Post a Comment