{"id":44478,"date":"2017-04-17T11:05:09","date_gmt":"2017-04-17T08:05:09","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=44478"},"modified":"2017-04-15T00:08:24","modified_gmt":"2017-04-14T21:08:24","slug":"xpath-search-id-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/","title":{"rendered":"Xpath Search by id Example"},"content":{"rendered":"<p>In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using IntelliJ 14.0.2 and Java 8.<\/p>\n<h2>1. Introduction<\/h2>\n<p>XPath is a W3C recommendation. XPath stands for XML Path Language. XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the path expressions you use with traditional computer file systems. XPath contains over 200 built-in functions. XPath is a major element in the XSLT standard. XPath includes over 200 built-in functions.\u00a0There are functions for string values, numeric values, booleans, date and time comparison, node manipulation, sequence manipulation, and much more.\u00a0Today XPath expressions can also be used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.<\/p>\n<h2>2. Search by Id<\/h2>\n<p>In this section we will see how to search an xml element using id. First we will discuss how to create a project using IntelliJ. Then we will write the code for it.<\/p>\n<h3>2.1 Creating project in IntelliJ<\/h3>\n<p>Open IntelliJ and click on File =&gt; New Project&#8230; In the New Project window choose Java.<\/p>\n<p><figure id=\"attachment_44516\" aria-describedby=\"caption-attachment-44516\" style=\"width: 736px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Java-Project.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44516\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Java-Project.jpg\" alt=\"\" width=\"736\" height=\"654\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Java-Project.jpg 736w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Java-Project-300x267.jpg 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/a><figcaption id=\"caption-attachment-44516\" class=\"wp-caption-text\">Figure 1. New Java Project<\/figcaption><\/figure><\/p>\n<p>Click Next. On the next window click Next. Give the Project name and the location of the project. and click Finish.<\/p>\n<p><figure id=\"attachment_44517\" aria-describedby=\"caption-attachment-44517\" style=\"width: 736px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-details.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44517\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-details.jpg\" alt=\"\" width=\"736\" height=\"654\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-details.jpg 736w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-details-300x267.jpg 300w\" sizes=\"(max-width: 736px) 100vw, 736px\" \/><\/a><figcaption id=\"caption-attachment-44517\" class=\"wp-caption-text\">Figure 2. Project Details<\/figcaption><\/figure><\/p>\n<p>IntelliJ will create the default structure of the project as below:<\/p>\n<p><figure id=\"attachment_44518\" aria-describedby=\"caption-attachment-44518\" style=\"width: 342px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-Structure.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44518\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-Structure.jpg\" alt=\"\" width=\"342\" height=\"680\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-Structure.jpg 342w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Project-Structure-151x300.jpg 151w\" sizes=\"(max-width: 342px) 100vw, 342px\" \/><\/a><figcaption id=\"caption-attachment-44518\" class=\"wp-caption-text\">Figure 3. Project Structure<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h3>2.2 Create New Class<\/h3>\n<p>In this section we will learn how to create a new java class in IntelliJ. First we are going to create a new package. Right click on the &#8216;src&#8217; folder and choose New =&gt; Package.<\/p>\n<p><figure id=\"attachment_44519\" aria-describedby=\"caption-attachment-44519\" style=\"width: 479px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Create-New-Java-Package.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44519\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Create-New-Java-Package.jpg\" alt=\"\" width=\"479\" height=\"498\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Create-New-Java-Package.jpg 479w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Create-New-Java-Package-289x300.jpg 289w\" sizes=\"(max-width: 479px) 100vw, 479px\" \/><\/a><figcaption id=\"caption-attachment-44519\" class=\"wp-caption-text\">Figure 4. Create New Java Package<\/figcaption><\/figure><\/p>\n<p>In the pop-up enter the new package name and click OK. IntelliJ will create the given package in the &#8216;src&#8217; folder.<\/p>\n<p><figure id=\"attachment_44521\" aria-describedby=\"caption-attachment-44521\" style=\"width: 418px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Package-Name.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44521\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Package-Name.jpg\" alt=\"\" width=\"418\" height=\"224\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Package-Name.jpg 418w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Package-Name-300x160.jpg 300w\" sizes=\"(max-width: 418px) 100vw, 418px\" \/><\/a><figcaption id=\"caption-attachment-44521\" class=\"wp-caption-text\">Figure 5. Package Name<\/figcaption><\/figure><\/p>\n<p>Now right click on the package and choose New =&gt; Java Class. Enter the class name and click OK.<\/p>\n<p><figure id=\"attachment_44522\" aria-describedby=\"caption-attachment-44522\" style=\"width: 348px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Class.jpg\"><img decoding=\"async\" class=\"size-full wp-image-44522\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Class.jpg\" alt=\"\" width=\"348\" height=\"224\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Class.jpg 348w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/New-Class-300x193.jpg 300w\" sizes=\"(max-width: 348px) 100vw, 348px\" \/><\/a><figcaption id=\"caption-attachment-44522\" class=\"wp-caption-text\">Figure 6. Create New Class<\/figcaption><\/figure><\/p>\n<h3>2.3. Code<\/h3>\n<p>In this section we will start coding for the example. Create a new XML file in the same directory where you java class is. You can create the XML at some other place as well and give the relevant path but for simplicity purpose we will create the XML in the same directory. To create the xml file right click on the package which you just created and choose New =&gt; File. Enter the file name and click OK.<\/p>\n<p>The XML which we are going to use for this example looks as below:<\/p>\n<p><em><span style=\"text-decoration: underline;\">test.xml<\/span><\/em><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?&gt;\r\n&lt;Persons&gt;\r\n  &lt;person id=\"345623\"&gt;\r\n    &lt;fullName&gt;Steve Jones&lt;\/fullName&gt;\r\n    &lt;address&gt;43 North wing, Washington&lt;\/address&gt;\r\n    &lt;dateOfBirth&gt;21 March 2001&lt;\/dateOfBirth&gt;\r\n  &lt;\/person&gt;\r\n  &lt;person id=\"972376\"&gt;\r\n    &lt;fullName&gt;Sachin Tendulkar&lt;\/fullName&gt;\r\n    &lt;address&gt;3 Pahaar gang, Bombay&lt;\/address&gt;\r\n    &lt;dateOfBirth&gt;21 March 1982&lt;\/dateOfBirth&gt;\r\n  &lt;\/person&gt;\r\n&lt;\/Persons&gt;\r\n<\/pre>\n<p>Now we will write a simple java code to find an element in this xml using the attribute (id). First we will show you the full java code then we will explain what is going on in the code.<\/p>\n<p><em><span style=\"text-decoration: underline;\">XPathSearchById.java<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\r\n\r\nimport org.w3c.dom.Node;\r\nimport org.xml.sax.InputSource;\r\n\r\nimport javax.xml.xpath.XPath;\r\nimport javax.xml.xpath.XPathConstants;\r\nimport javax.xml.xpath.XPathExpressionException;\r\nimport javax.xml.xpath.XPathFactory;\r\n\r\n\/**\r\n* Created by Meraj on 14\/04\/2017.\r\n*\/\r\npublic class XPathSearchById {\r\n\r\n  public static void main(String[] args) {\r\n    XPath xpath = XPathFactory.newInstance().newXPath();\r\n    String expression = \"\/Persons\/person[@id=972376]\/fullName\";\r\n    InputSource inputSource = new InputSource(\"src\/\/com\/\/javacodegeeks\/\/test.xml\");\r\n    try {\r\n      Node node = (Node) xpath.evaluate(expression, inputSource, XPathConstants.NODE);\r\n      System.out.println(node.getTextContent());\r\n    } catch (XPathExpressionException e) {\r\n      e.printStackTrace();\r\n    }\r\n  }\r\n}<\/pre>\n<p>We first create the <code>javax.xml.xpath.XPath<\/code> instance using the\u00a0<code>javax.xml.xpath.XPathFactory<\/code> by calling the\u00a0<code>newInstance()<\/code> method of the factory class. Then we define the XPath expression where we use the <code>@id<\/code> attribute to find the person node with the give id attribute. Then we define the input source by passing the location of our xml file. This class allows a SAX application to encapsulate information about an input source in a single object, which may include a public identifier, a system identifier, a byte stream (possibly with a specified encoding), and\/or a character stream.<br \/>\nThen we will call the <code>xpath.evaluate()<\/code> to evaluate an XPath expression in the context of the specified <code>InputSource<\/code> and return the result as the specified type.<\/p>\n<h2>3. Conclusion<\/h2>\n<p>In this article we learned about XPath and also how to search an element using the id. We discussed how to create a simple \u00a0java project in IntelliJ and how how to write a simple program to find the element in an xml using XPath.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using IntelliJ 14.0.2 and Java 8. 1. Introduction XPath is a W3C recommendation. XPath stands for XML Path Language. XPath uses path expressions &hellip;<\/p>\n","protected":false},"author":34,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[],"class_list":["post-44478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-xpath"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Xpath Search by id Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Xpath Search by id Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-04-17T08:05:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mohammad Meraj Zia\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mohammad Meraj Zia\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\"},\"author\":{\"name\":\"Mohammad Meraj Zia\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed\"},\"headline\":\"Xpath Search by id Example\",\"datePublished\":\"2017-04-17T08:05:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\"},\"wordCount\":671,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"XPath\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\",\"name\":\"Xpath Search by id Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2017-04-17T08:05:09+00:00\",\"description\":\"In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"xml\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"XPath\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/xpath\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Xpath Search by id Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed\",\"name\":\"Mohammad Meraj Zia\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg\",\"caption\":\"Mohammad Meraj Zia\"},\"description\":\"Senior Java Developer\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mohammad-zia\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Xpath Search by id Example - Java Code Geeks","description":"In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/","og_locale":"en_US","og_type":"article","og_title":"Xpath Search by id Example - Java Code Geeks","og_description":"In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-04-17T08:05:09+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Mohammad Meraj Zia","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mohammad Meraj Zia","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/"},"author":{"name":"Mohammad Meraj Zia","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed"},"headline":"Xpath Search by id Example","datePublished":"2017-04-17T08:05:09+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/"},"wordCount":671,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["XPath"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/","name":"Xpath Search by id Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2017-04-17T08:05:09+00:00","description":"In this article we will learn how to search for an element (by id) in an XML using XPath. We will make use of IDEA IntelliJ to work on this. I am using","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-search-id-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"xml","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/"},{"@type":"ListItem","position":5,"name":"XPath","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/xml\/xpath\/"},{"@type":"ListItem","position":6,"name":"Xpath Search by id Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed","name":"Mohammad Meraj Zia","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/IMG-20200324-WA0003-96x96.jpg","caption":"Mohammad Meraj Zia"},"description":"Senior Java Developer","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/mohammad-zia\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=44478"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/44478\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=44478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=44478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=44478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}