Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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.

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.

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

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

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.

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

Code –

 net.sf.saxon 

 saxon-XPath 

 8.7 

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

Code –

 ABC 

 Pune 

 PQR 

 Mumbai 

: student>

 XYZ 

 Pune 

: student>

 BCD 

 Pune 

: student>

 CBD 

 Chennai 

: student>

: students>

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);

}

}

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 ()
  • 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 –

     ABC 

    Examples

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

    Code –

     ABC 
    
     Pune 
    
     PQR 
    
     Mumbai 
    
    

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

    Code –

    public class XPath_localname
    
    {
    
    …..
    
    }

    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

    The post XPath local-name appeared first on EDUCBA.



    This post first appeared on Best Online Training & Video Courses | EduCBA, please read the originial post: here

    Share the post

    XPath local-name

    ×

    Subscribe to Best Online Training & Video Courses | Educba

    Get updates delivered right to your inbox!

    Thank you for your subscription

    ×