EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials XML Tutorial XPath local-name
Secondary Sidebar
XML Tutorial
  • Xpath
    • What is XPath?
    • XPath namespace
    • XPath for JSON
    • XPath Last Element
    • Xpath Substring
    • XPath First Element
    • XPath local-name
    • XPath Multiple Attributes
    • XPath Matches
    • XPath Position
    • XPath Index
    • XPath regex
    • XPath id contains
    • XPath innertext
    • XPath Multiple Conditions
    • XPath Helper
    • XPath Generator
    • XPath ID
    • XPath Locator
  • Basic
    • What is XML?
    • XML Tags
    • XML URL
    • XPath Sibling
    • XML root element
    • XML Encryption
    • XML Parsing php
    • xml parsing with java
    • Dataset XML
    • XML Parser in C#
    • XML Tree
    • XML boolean
    • XML sitemap
    • XML Array
    • XML reserved characters
    • XML Viewer
    • XML Uses
    • XML Special Characters
    • XML generator
    • XML file format
    • XML DOM
    • XML ampersand
    • XML Mapping
    • XML File
    • XML Element
    • XML HttpRequest
    • XML XSD
    • XML Schema
    • XML Namespaces
    • XML Comments
    • XML Attributes
    • XML Encoding
    • XML Validation
    • XML CDATA
    • XML Database
    • XML Technologies
    • XML Error
    • XML DTD
    • XML Date
    • XML Parsers
    • String in XML
    • XML with CSS
    • XML Versions
    • XML Features
    • XML Commands
    • Servlet web.xml
    • XPath Injection
    • XPath Functions
    • XPath starts-with
    • XPath Selector
    • XPath Count
    • XPath XML
    • XML Parsing in Oracle
    • XML parsing in python

XPath local-name

XPath local-name

Definition of XPath local-name

XPath local-name is a function which is returning the string name for the first node in a given set of nodes. Basically, XPath local-name will be returning the local part of the name as an argument string which is either the zero-length which is contained in a form of lexical. The form of zero-argument is deterministic, focus dependent, and also contains the context-dependent into the XPath.

Overview of XPath local-name

XPath local-name function will be returning the string. If the argument is omitted in XPath local-name it will default to the items of context. The function behavior of the XPath local name is omitted arguments is same as context item which is passed into the argument. After supplying the argument the empty sequence of functions will return the string of zero length. After identifying the node $arg argument the function will return the length of the zero string. Then otherwise this function will be returning the local part of the qname which was expanded and the node is identified by using the argument.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

How to use XPath local-name?

  • As we know that XPath local name function will return the string which was representing the node-set function name.
  • Below is the syntax of XPath local-name which shows how we can use the XPath local name.

Syntax –

Local-name([set-of-node])
  • In the above syntax node-set is the optional parameter, and the local name into the first node-set is returning the node-set value. If this argument will be omitted then the context of the current node is used.
  • The below steps show how we can use the XPath local name as follows. We are creating the project name as XPathLocalName.

1. In this step, we are creating the project template of XPath local-name in spring boot. We have provided project group name as com.example, artifact name as XPathLocalName, project name as XPathLocalName, and selected java version as 11. We are defining the version of spring boot as 2.6.7.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,883 ratings)

Group – com.example

Artifact name – XPathLocalName

Name – XPathLocalName

Spring boot – 2.6.7

Project – Maven

Java – 11

Package name – com.example. XPathLocalName

Project Description – Project for XPathLocalName

Dependencies – Spring web

Packaging – Jar

ui

2. In this step we are extracting the downloaded project and opening the same by using the spring tool suite as follows.

pr

3. In this step we are checking all the project structures and their files are as follows. Also, we are checking whether that pom.xml file is created or not. Suppose this file is not created then we need to create the same manually. In the below example this file is created, so we have no need to create it manually.

ng

4. In this step we are adding the dependency in XPath local name project. We are adding a dependency.

Code –

<dependency>
<groupId> net.sf.saxon </groupId>
<artifactId> saxon-XPath </artifactId>
<version> 8.7 </version>
</dependency>

khf

5. After creating the structure of project in this step we are creating the stud.xml file are as follows.

Code –

<?xml version = "1.0" encoding = "UTF-8"?>
<cr:students xmlns:cr = "example.com/">
<cr:student std = 1>
<stud_name> ABC </stud_name>
<addr> Pune </addr>
</cr:student>
<cr:student std = 2>
<stud_name> PQR </stud_name>
<addr> Mumbai </addr>
</cr : student>
<cr:student std = 3>
<stud_name> XYZ </stud_name>
<addr> Pune </addr>
</cr : student>
<cr : student type = 4>
<stud_name> BCD </stud_name>
<addr> Pune </addr>
</cr : student>
<cr : student std = 5>
<stud_name> CBD </stud_name>
<addr> Chennai </addr>
</cr : student>
</cr : students>

mbn

6. After creating the stud.xml file now we are creating the local name function are as follows.

Code –

public class XPath_localname
{
DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance ();
DBF.setNamespaceAware (true);
DocumentBuilder DB = DBF.newDocumentBuilder ();
Document doc = (Document) DB.parse ("stud.xml");
XPathFactory XF = XPathFactory.newInstance();
XPath XPath = XF.newXPath();
XPathExpression xexpr = XPath.compile ("//*[local-name ()='student']/stud_name/text()");
String type = (String) xexpr.evaluate (doc, XPathConstants.STRING);
System.out.println ("Name of student : " + type);
}
}

sewe

ert

XPath local-name function

XPath local name provides the node set function. Basically XPath contains the following function and XPath local-name contains the node-set function in it.

  • Node sets
  • Strings
  • Booleans
  • Numbers

At the time of working with the node-set function, the current node-set is passed as a parameter. Below is describing the node-set function as follows.

  • Number last () – This function is used to return the last item from the node-set which was current.

Example –

[last ()]
  • Number position () – This function is used to return a current item from the node-set which was current.

Example –

[position () < 5]
  • Number count (node-set) – This function is used to return a number of items from the node-set argument.

Example –

Count (article)

  • Node set id (object) – It will return the element with the ID which was specified.
  • String local-name (node-set) – It is used to return the non-namespace portion of the node.
  • String namespace-uri (node-set) – It will return the URI node name from the node-set.
  • String name (node-set) – It is used to return the complex structure node name in XPath local name.
  • Node set evaluate (string) – It will return a node-set result from the expression of XPath which is defined in the argument.
  • Node-set instance (string) – It will returning a content of instance of named xml.

Below is the example function of XPath local name.

Code –

<Employee>
<Organization>
<EmpName> ABC </EmpName>
</Organization>
</Employee>

XPath local-name 345

Examples

  • Below is the example of XPath local name as follows. In below we are creating emp.xml file as follows.

Code –

<?xml version = "1.0" encoding = "UTF-8"?>
<cr:Employees xmlns:cr = "example.com/">
<cr:Employee ID = 1>
<Emp_name> ABC </Emp_name>
<addr> Pune </addr>
</cr:Employee>
<cr:Employee ID = 2>
<Emp_name> PQR </Emp_name>
<addr> Mumbai </addr>
</cr:Employee>
</cr:Employees>

XPath local-name vas

  • Now we are creating the XPath local name function as follows.

Code –

public class XPath_localname
{
…..
}

XPath local-name nas

XPath local-name bvfgh

Conclusion

XPath local-name function will be returning the string. If the argument is omitted in XPath local-name it will default to the items of context. XPath local-name is a function which is returning the string name for the first node in a given set of nodes.

Recommended Articles

This is a guide to XPath local-name. Here we discuss the Definition, overviews, How to use XPath local-name? and examples with code implementation respectively. You may also have a look at the following articles to learn more –

  1. XPath regex
  2. XPath Sibling
  3. XPath finder
  4. XPath contains
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more