{"id":20200,"date":"2015-02-25T11:00:12","date_gmt":"2015-02-25T09:00:12","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=20200"},"modified":"2015-02-23T22:33:38","modified_gmt":"2015-02-23T20:33:38","slug":"xpath-starts-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/","title":{"rendered":"XPath starts-with example"},"content":{"rendered":"<p>In this example we will learn how to use <code>starts-with<\/code> function of XPath. We will start with the introduction of XPath &#8211; what it is and how to use it, then we will see the working model of &#8216;starts-with&#8217; function.<\/p>\n<p>Tools and technologies used in this example are Java 1.7, Maven, Intellij.<\/p>\n<h2>1. Overview<\/h2>\n<p><strong>XPath<\/strong> expression specifies a pattern that selects a set of XML nodes. XSLT templates then use those patterns when applying transformations.\u00a0The nodes in an XPath expression refer to more than just elements. They also refer to text and attributes, among other things. In fact, the XPath specification defines an abstract document model that defines seven kinds of nodes:<\/p>\n<ul>\n<li>Root<\/li>\n<li>Element<\/li>\n<li>Text<\/li>\n<li>Attribute<\/li>\n<li>Comment<\/li>\n<li>Processing instruction<\/li>\n<li>Namespace<\/li>\n<\/ul>\n<p>XPath also provides rules for converting a node in an XML document object model (DOM) tree to a boolean, double, or string value.\u00a0XPath is a W3C-defined language and an official W3C recommendation; the W3C hosts the XML Path Language (XPath) Version 1.0 specification.<\/p>\n<h2>2. XPath Expressions<\/h2>\n<p>An XPath\u00a0<em>expression<\/em>\u00a0is composed of a\u00a0<em>location path<\/em>\u00a0and one or more optional\u00a0<em>predicates<\/em>. Expressions may also include XPath variables.<\/p>\n<p>The following is an example of a simple XPath expression:<\/p>\n<p><code>\/Country\/City<\/code><\/p>\n<p>This example would select the\u00a0<code>&lt;City&gt;<\/code>\u00a0element in an XML document<\/p>\n<h2>3. Project Structure<\/h2>\n<p>Below is the project structure used in this example<\/p>\n<p><figure id=\"attachment_20201\" aria-describedby=\"caption-attachment-20201\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Project-Structure1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-20201\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Project-Structure1.jpg\" alt=\"Figure 1. Project Structure\" width=\"350\" height=\"382\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Project-Structure1.jpg 350w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/Project-Structure1-275x300.jpg 275w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/a><figcaption id=\"caption-attachment-20201\" class=\"wp-caption-text\">Figure 1. Project Structure<\/figcaption><\/figure><\/p>\n<h2>4. XLM file<\/h2>\n<p>Below is the xml file representing Users. Each user has got a unique UserId, \u00a0name, address, sex, Date Of Birth and email.<\/p>\n<p><span style=\"text-decoration: underline\"><em>user.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;Users&gt;\r\n    &lt;User&gt;\r\n        &lt;UserId&gt;12345&lt;\/UserId&gt;\r\n        &lt;Name&gt;\r\n            &lt;FirstName&gt;Maden&lt;\/FirstName&gt;\r\n            &lt;MiddleName&gt;Over&lt;\/MiddleName&gt;\r\n            &lt;Surname&gt;Gulliver&lt;\/Surname&gt;\r\n        &lt;\/Name&gt;\r\n        &lt;Address&gt;\r\n            &lt;FirstLineOfAddress&gt;Oxford Street&lt;\/FirstLineOfAddress&gt;\r\n            &lt;SecondLineOfAddress&gt;&lt;\/SecondLineOfAddress&gt;\r\n            &lt;City&gt;London&lt;\/City&gt;\r\n            &lt;County&gt;Middlesex&lt;\/County&gt;\r\n            &lt;Country&gt;United Kingdom&lt;\/Country&gt;\r\n        &lt;\/Address&gt;\r\n        &lt;Sex&gt;Male&lt;\/Sex&gt;\r\n        &lt;DateOfBirth&gt;01\/02\/1967&lt;\/DateOfBirth&gt;\r\n        &lt;Email&gt;&lt;\/Email&gt;\r\n    &lt;\/User&gt;\r\n    &lt;User&gt;\r\n        &lt;UserId&gt;56789&lt;\/UserId&gt;\r\n        &lt;Name&gt;\r\n            &lt;FirstName&gt;Tom&lt;\/FirstName&gt;\r\n            &lt;MiddleName&gt;Cruise&lt;\/MiddleName&gt;\r\n            &lt;Surname&gt;Kidman&lt;\/Surname&gt;\r\n        &lt;\/Name&gt;\r\n        &lt;Address&gt;\r\n            &lt;FirstLineOfAddress&gt;Reagent Street&lt;\/FirstLineOfAddress&gt;\r\n            &lt;SecondLineOfAddress&gt;&lt;\/SecondLineOfAddress&gt;\r\n            &lt;City&gt;New York&lt;\/City&gt;\r\n            &lt;County&gt;&lt;\/County&gt;\r\n            &lt;Country&gt;United States&lt;\/Country&gt;\r\n        &lt;\/Address&gt;\r\n        &lt;Sex&gt;Female&lt;\/Sex&gt;\r\n        &lt;DateOfBirth&gt;02\/03\/1978&lt;\/DateOfBirth&gt;\r\n        &lt;Email&gt;&lt;\/Email&gt;\r\n    &lt;\/User&gt;\r\n    &lt;User&gt;\r\n        &lt;UserId&gt;72638&lt;\/UserId&gt;\r\n        &lt;Name&gt;\r\n            &lt;FirstName&gt;Amitabh&lt;\/FirstName&gt;\r\n            &lt;MiddleName&gt;&lt;\/MiddleName&gt;\r\n            &lt;Surname&gt;Bachchan&lt;\/Surname&gt;\r\n        &lt;\/Name&gt;\r\n        &lt;Address&gt;\r\n            &lt;FirstLineOfAddress&gt;Panama Street&lt;\/FirstLineOfAddress&gt;\r\n            &lt;SecondLineOfAddress&gt;&lt;\/SecondLineOfAddress&gt;\r\n            &lt;City&gt;Mumbai&lt;\/City&gt;\r\n            &lt;County&gt;&lt;\/County&gt;\r\n            &lt;Country&gt;India&lt;\/Country&gt;\r\n        &lt;\/Address&gt;\r\n        &lt;Sex&gt;Male&lt;\/Sex&gt;\r\n        &lt;DateOfBirth&gt;05\/04\/1999&lt;\/DateOfBirth&gt;\r\n        &lt;Email&gt;amitabh.bachchan@asv.com&lt;\/Email&gt;\r\n    &lt;\/User&gt;\r\n&lt;\/Users&gt;<\/pre>\n<h2>5. Java file<\/h2>\n<p>Below is the java file which will use XPath to extract information from the <code>User.xml.<\/code> We will try to extract the country names that starts with &#8216;<em>United<\/em>&#8216;.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>ExampleXPathStartsWith.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks;\r\n\r\nimport org.w3c.dom.Document;\r\nimport org.w3c.dom.Node;\r\nimport org.w3c.dom.NodeList;\r\nimport org.xml.sax.SAXException;\r\n\r\nimport javax.xml.parsers.DocumentBuilder;\r\nimport javax.xml.parsers.DocumentBuilderFactory;\r\nimport javax.xml.parsers.ParserConfigurationException;\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\nimport java.io.FileNotFoundException;\r\nimport java.io.IOException;\r\n\r\n\/**\r\n * Example class for describing how the XPath starts-with function works.\r\n * @author JavaCodeGeeks\r\n *\/\r\npublic class ExampleXPathStartsWith {\r\n\r\n    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();\r\n    DocumentBuilder builder = null;\r\n\r\n    public static void main(String q[]) {\r\n        ExampleXPathStartsWith exampleXPathStartsWith = new ExampleXPathStartsWith();\r\n        exampleXPathStartsWith.execute();\r\n    }\r\n\r\n    public void execute() {\r\n        try {\r\n            builder = builderFactory.newDocumentBuilder();\r\n            Document document = builder.parse(this.getClass().getResourceAsStream(\"\/user.xml\"));\r\n            XPath xPath =  XPathFactory.newInstance().newXPath();\r\n            String expression = \"\/\/User\/Address\/Country[starts-with(.,'United')]\";\r\n\r\n            \/\/read a string value\r\n            NodeList nl = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET);\r\n            for(int i=0; i &lt; nl.getLength() ; i++) {\r\n                Node node = nl.item(i);\r\n                System.out.println(node.getTextContent());\r\n            }\r\n        } catch (ParserConfigurationException e) {\r\n            e.printStackTrace();\r\n        } catch (SAXException e) {\r\n            e.printStackTrace();\r\n        } catch (FileNotFoundException e) {\r\n            e.printStackTrace();\r\n        } catch (IOException e) {\r\n            e.printStackTrace();\r\n        } catch (XPathExpressionException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }\r\n}<\/pre>\n<p>First we create a reference of\u00a0<code>DocumentBuilderFactory<\/code> by calling the static\u00a0<code>newInstance<\/code> method of it.<\/p>\n<pre class=\"brush:java\">DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();<\/pre>\n<p>Then we create a <code>DocumentBuilder<\/code> object by calling <code>newDocumentBuilder()<\/code> method on the factory object.<\/p>\n<pre class=\"brush:java\">DocumentBuilder builder = builderFactory.newDocumentBuilder();<\/pre>\n<p>Then we call the <code>parse()<\/code> method on this builder object by passing in the xml file that we pant to parse.<\/p>\n<pre class=\"brush:java\">Document document = builder.parse(this.getClass().getResourceAsStream(\"\/user.xml\"));<\/pre>\n<p>Then we create a XPath object:<\/p>\n<pre class=\"brush:java\">XPath xPath =  XPathFactory.newInstance().newXPath();<\/pre>\n<p>We will call the compile() method on this XPath object by passing in the expression and then call the evaluate() method. This will return is the list of nodes from the target xml.<\/p>\n<pre class=\"brush:java\">NodeList nl = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET);<\/pre>\n<p>Then we will iterate these nodes to print the text content<\/p>\n<pre class=\"brush:java\">System.out.println(node.getTextContent());<\/pre>\n<h2>6. Output<\/h2>\n<p>Run the\u00a0ExampleXPathStartsWith.java file. \u00a0Below is the generated output.<\/p>\n<pre class=\"brush:bash\">United Kingdom\r\nUnited States\r\n\r\nProcess finished with exit code 0<\/pre>\n<h2>7. Download the source file<\/h2>\n<p>This was an example of <code>XPath starts-with<\/code> function.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:\u00a0<a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/02\/XPath-starts-with.zip\"><strong>XPath-starts-with.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath &#8211; what it is and how to use it, then we will see the working model of &#8216;starts-with&#8217; function. Tools and technologies used in this example are Java 1.7, Maven, Intellij. 1. Overview XPath &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-20200","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 starts-with example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath - what it is and how to use it, then\" \/>\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-starts-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"XPath starts-with example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath - what it is and how to use it, then\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-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=\"2015-02-25T09:00:12+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=\"5 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-starts-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/\"},\"author\":{\"name\":\"Mohammad Meraj Zia\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed\"},\"headline\":\"XPath starts-with example\",\"datePublished\":\"2015-02-25T09:00:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/\"},\"wordCount\":417,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-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-starts-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/\",\"name\":\"XPath starts-with example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2015-02-25T09:00:12+00:00\",\"description\":\"In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath - what it is and how to use it, then\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-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-starts-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 starts-with 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 starts-with example - Java Code Geeks","description":"In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath - what it is and how to use it, then","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-starts-example\/","og_locale":"en_US","og_type":"article","og_title":"XPath starts-with example - Java Code Geeks","og_description":"In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath - what it is and how to use it, then","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-02-25T09:00:12+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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/"},"author":{"name":"Mohammad Meraj Zia","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/442b4f9b8a4aa7e12376464fc354f8ed"},"headline":"XPath starts-with example","datePublished":"2015-02-25T09:00:12+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/"},"wordCount":417,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-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-starts-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/","name":"XPath starts-with example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2015-02-25T09:00:12+00:00","description":"In this example we will learn how to use starts-with function of XPath. We will start with the introduction of XPath - what it is and how to use it, then","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/xpath-starts-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-starts-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 starts-with 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\/20200","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=20200"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/20200\/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=20200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=20200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=20200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}