{"id":51271,"date":"2017-11-02T11:00:45","date_gmt":"2017-11-02T09:00:45","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=51271"},"modified":"2017-10-31T10:29:45","modified_gmt":"2017-10-31T08:29:45","slug":"java-xpathfactory-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/","title":{"rendered":"Java XPathFactory Example"},"content":{"rendered":"<p>In this example, we will see what is java <code>XPathFactory<\/code> and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic understanding of\u00a0XML. XML stands for eXtensible Markup Language, which is designed to store and transport data. It is both human and machine readable.<\/p>\n<h2>1. Introduction<\/h2>\n<p><code>XPathFactory<\/code> is an abstract class in java that extends<br \/>\n<code>java.lang.Object<\/code>.\u00a0An\u00a0<code>XPathFactory<\/code>\u00a0instance can be used to create<br \/>\n<code>XPath<\/code>\u00a0objects.\u00a0<code>XPath<\/code> is a standard syntax recommended by the W3C.<br \/>\n<code>XPath<\/code> is a major element in the XSLT standard that\u00a0can be used to navigate through expressions, elements and attributes in an XML document. <code>XPath<\/code> expressions help us to navigate to the desired node in an XML that we want to retrieve.<br \/>\nJava\u00a0classes\u00a0from\u00a0<code>java.xml.xpath<\/code>\u00a0package e.g.\u00a0XPath,\u00a0XPathFactory\u00a0and\u00a0XPathExpression are used to create and evaluate <code>Xpath<\/code> in Java.<\/p>\n<p>In this example, we will see how to use <code>XPathFactory<\/code>,\u00a0<code>newInstance()<\/code> method to get a <code>XPath<\/code> instance and traverse the XML.<\/p>\n<h2>2. Demonstration<\/h2>\n<p>Let us write a java program to demonstrate how to get a new <code>XPathFactory<\/code> instance, create <code>XPath<\/code> expression and how to execute <code>XPath<\/code> expression to retrieve text value, numeric and boolean value.<\/p>\n<h3>2.1 Creating a java project<\/h3>\n<p>Create a new java project in eclipse using File -&gt; New -&gt;Java Project. Enter the project name &#8220;XPathFactoryExample&#8221; and a new java project should get created. Refer screenshot below.<\/p>\n<p><figure id=\"attachment_51622\" aria-describedby=\"caption-attachment-51622\" style=\"width: 809px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/EclipseProjectStr.jpg\"><img decoding=\"async\" class=\"wp-image-51622 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/EclipseProjectStr.jpg\" alt=\"\" width=\"809\" height=\"285\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/EclipseProjectStr.jpg 809w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/EclipseProjectStr-300x106.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/EclipseProjectStr-768x271.jpg 768w\" sizes=\"(max-width: 809px) 100vw, 809px\" \/><\/a><figcaption id=\"caption-attachment-51622\" class=\"wp-caption-text\">Fig 1: Creating a Java project<\/figcaption><\/figure><\/p>\n<h3>2.2 Creating a new\u00a0XPathFactoryExample class<\/h3>\n<p>Create a new java class naming <code>XPathFactoryExample.java<\/code> using, Right Click on java project-&gt;New-&gt;Class.<\/p>\n<p><figure id=\"attachment_51623\" aria-describedby=\"caption-attachment-51623\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateNewClass.jpg\"><img decoding=\"async\" class=\"wp-image-51623 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateNewClass.jpg\" alt=\"\" width=\"860\" height=\"153\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateNewClass.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateNewClass-300x53.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateNewClass-768x137.jpg 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-51623\" class=\"wp-caption-text\">Fig 2: Create new java class<\/figcaption><\/figure><\/p>\n<h3>2.3 XPathFactoryExample.java<\/h3>\n<p>After creating a new class,\u00a0Refer the code below for\u00a0<code>XPathFactoryExample.java<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>XPathFactoryExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.xpath.example;\r\n\r\nimport java.io.IOException;\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.XPathExpression;\r\nimport javax.xml.xpath.XPathExpressionException;\r\nimport javax.xml.xpath.XPathFactory;\r\nimport org.w3c.dom.Document;\r\nimport org.w3c.dom.NodeList;\r\nimport org.xml.sax.SAXException;\r\n\r\n\/\/XPathFactoryExample -Java example\r\npublic class XPathFactoryExample { \r\n\r\npublic void xPathProcessor() throws SAXException, IOException, XPathExpressionException, ParserConfigurationException {\r\n   \/\/ Create DocumentBuilderFactory for reading xml file DocumentBuilderFactory factory = \r\n   DocumentBuilderFactory.newInstance(); \r\n   DocumentBuilder builder = factory.newDocumentBuilder(); \r\n   Document doc = builder.parse(\"smartphone.xml\");\r\n\r\n   \/\/ Create XPathFactory for creating XPath Object \r\n   XPathFactory xPathFactory = XPathFactory.newInstance();\r\n   \/\/ Create XPath object from XPathFactory \r\n   XPath xpath = xPathFactory.newXPath();\r\n   \/\/ Compile the XPath expression for getting all brands \r\n   XPathExpression xPathExpr = xpath.compile(\"\/smartphones\/smartphone\/brand\/text()\");\r\n\r\n   \/\/ XPath text example : executing xpath expression in java Object\r\n   result = xPathExpr.evaluate(doc, XPathConstants.NODESET); \r\n   System.out.println(\"Java Xpath text example: All brands of popular smartphones \"); \r\n   printXpathResult(result);\r\n\r\n   \/\/ get all models by xpath expression in java \r\n   xPathExpr = xpath.compile(\"\/smartphones\/smartphone\/model\/text()\"); \r\n   result = xPathExpr.evaluate(doc, XPathConstants.NODESET); \r\n   System.out.println(\"Java Xpath text example: All popular smartphone model \"); \r\n   printXpathResult(result);\r\n\r\n   \/\/ XPath count example : XPath expression to count elements in xml \r\n   xPathExpr = xpath.compile(\"count(\/smartphones\/smartphone)\"); \r\n   Double count = (Double) xPathExpr.evaluate(doc, XPathConstants.NUMBER); \r\n   System.out.println(\"XPath count example: How many Smartphones we have: \"); \r\n   System.out.println(\"Count of elements: \" + count);\r\n\r\n   \/\/ XPath conditional exampl e: Do we have any HTC smartphone xPath\r\n   Expr = xpath.compile(\"count(\/smartphones\/smartphone[brand='HTC']) &gt; 0\"); \r\n   Boolean test = (Boolean) xPathExpr.evaluate(doc, XPathConstants.BOOLEAN); \r\n   System.out.println(\"XPath boolean example: Do we have any HTC smartphone \"); \r\n   System.out.println(test);\r\n}\r\n\r\n\/** \r\n* Method to print result on console \r\n* @param result \r\n*\/ \r\npublic void printXpathResult(Object result) { \r\n   NodeList nodes = (NodeList) result; \r\n   for (int i = 0; i &lt; nodes.getLength(); i++) { \r\n   System.out.println(nodes.item(i).getNodeValue()); \r\n   } \r\n}\r\n\r\n\/\/Main class to run the example. \r\npublic static void main(String[] args) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException {\r\n   XPathFactoryExample xPathExample = new XPathFactoryExample(); \r\n   xPathExample.xPathProcessor(); \r\n   }\r\n}\u00a0\r\n<\/pre>\n<h3>2.4 Creating smartphone.xml<\/h3>\n<p>Create a new xml by Right click on Java project -&gt;New -&gt;Other. Search for XML.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><figure id=\"attachment_51627\" aria-describedby=\"caption-attachment-51627\" style=\"width: 780px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/newXml.jpg\"><img decoding=\"async\" class=\"wp-image-51627 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/newXml.jpg\" alt=\"\" width=\"780\" height=\"450\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/newXml.jpg 780w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/newXml-300x173.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/newXml-768x443.jpg 768w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/a><figcaption id=\"caption-attachment-51627\" class=\"wp-caption-text\">Fig 3: Creating new xml<\/figcaption><\/figure><\/p>\n<p>Select XML -&gt; XML File and click Next.<\/p>\n<p><figure id=\"attachment_51628\" aria-describedby=\"caption-attachment-51628\" style=\"width: 853px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateXML.jpg\"><img decoding=\"async\" class=\"wp-image-51628 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateXML.jpg\" alt=\"\" width=\"853\" height=\"556\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateXML.jpg 853w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateXML-300x196.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/CreateXML-768x501.jpg 768w\" sizes=\"(max-width: 853px) 100vw, 853px\" \/><\/a><figcaption id=\"caption-attachment-51628\" class=\"wp-caption-text\">Fig 4: New XML file<\/figcaption><\/figure><\/p>\n<p>Select the recently created project and enter the XML filename i.e. smartphone.xml that we\u00a0are using in our <code>XPathFactory.java<\/code> class and click Finish. A new XML gets created in the project root directory. Refer screenshot below.<\/p>\n<p><figure id=\"attachment_51631\" aria-describedby=\"caption-attachment-51631\" style=\"width: 850px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/XMLFileName11.jpg\"><img decoding=\"async\" class=\"wp-image-51631 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/XMLFileName11.jpg\" alt=\"\" width=\"850\" height=\"720\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/XMLFileName11.jpg 850w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/XMLFileName11-300x254.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/XMLFileName11-768x651.jpg 768w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><figcaption id=\"caption-attachment-51631\" class=\"wp-caption-text\">Fig 5: XML filename<\/figcaption><\/figure><\/p>\n<h3>2.5 Project directory structure<\/h3>\n<p>Refer project directory structure below.<\/p>\n<p><figure id=\"attachment_51632\" aria-describedby=\"caption-attachment-51632\" style=\"width: 483px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ProjectDirStructure.jpg\"><img decoding=\"async\" class=\"wp-image-51632 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ProjectDirStructure.jpg\" alt=\"\" width=\"483\" height=\"378\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ProjectDirStructure.jpg 483w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/ProjectDirStructure-300x235.jpg 300w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/a><figcaption id=\"caption-attachment-51632\" class=\"wp-caption-text\">Fig 6: Project directory structure<\/figcaption><\/figure><\/p>\n<h3>2.6 smartphone.xml content<\/h3>\n<p>Here is the content of smartphone.xml.<\/p>\n<p><span style=\"text-decoration: underline\"><em>smartphone.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml; wrap-lines:false\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;smartphones&gt; \r\n   &lt;smartphone&gt; \r\n      &lt;brand&gt; \r\n         &lt;text&gt;\r\n            Samsung           \r\n         &lt;\/text&gt; \r\n      &lt;\/brand&gt; \r\n      &lt;model&gt; \r\n          Note3 \r\n      &lt;\/model&gt; \r\n   &lt;\/smartphone&gt; \r\n   &lt;smartphone&gt; \r\n      &lt;brand&gt; \r\n         &lt;text&gt; \r\n            Apple \r\n         &lt;\/text&gt; \r\n      &lt;\/brand&gt; \r\n      &lt;model&gt; \r\n         IPhone8 \r\n      &lt;\/model&gt; \r\n   &lt;\/smartphone&gt;\r\n&lt;\/smartphones&gt;\r\n<\/pre>\n<h3>2.7 Eclipse output<\/h3>\n<p>Run the project by Right click on project -&gt; Run As -&gt; Java Application.<\/p>\n<p><figure id=\"attachment_51672\" aria-describedby=\"caption-attachment-51672\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunJavaProject.jpg\"><img decoding=\"async\" class=\"wp-image-51672 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunJavaProject.jpg\" alt=\"\" width=\"860\" height=\"123\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunJavaProject.jpg 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunJavaProject-300x43.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/RunJavaProject-768x110.jpg 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-51672\" class=\"wp-caption-text\">Fig 7: Run Java Project<\/figcaption><\/figure><\/p>\n<p>We can see the output as below when we run the project.<\/p>\n<p><figure id=\"attachment_51674\" aria-describedby=\"caption-attachment-51674\" style=\"width: 671px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/eclipseOutput.jpg\"><img decoding=\"async\" class=\"wp-image-51674 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/eclipseOutput.jpg\" alt=\"\" width=\"671\" height=\"531\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/eclipseOutput.jpg 671w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/eclipseOutput-300x237.jpg 300w\" sizes=\"(max-width: 671px) 100vw, 671px\" \/><\/a><figcaption id=\"caption-attachment-51674\" class=\"wp-caption-text\">Fig 7: Project output<\/figcaption><\/figure><\/p>\n<h2>3. Conclusion<\/h2>\n<p>The output shows, how we get <code>XPathFactory<\/code> instance, and parse the <code>smartphone.xml<\/code> file. We have also seen how a new <code>XPath<\/code> object has been created and a\u00a0<code>XPathExpression<\/code> has been executed\u00a0to retrieve text value, numeric value and boolean value.<\/p>\n<h2>4. Download the Eclipse Project<\/h2>\n<p>This was an example of using XPathFactory.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:<a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/10\/XpathFactoryExample.zip\"> <strong>XpathFactoryExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic understanding of\u00a0XML. XML stands for eXtensible Markup Language, which is designed to store and transport data. It is both human and machine readable. 1. Introduction XPathFactory is &hellip;<\/p>\n","protected":false},"author":125,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[1682],"class_list":["post-51271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-xpath","tag-xpathfactory"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java XPathFactory Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic\" \/>\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\/java-xpathfactory-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java XPathFactory Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-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-11-02T09:00:45+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=\"Neha Goel\" \/>\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=\"Neha Goel\" \/>\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\/java-xpathfactory-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/\"},\"author\":{\"name\":\"Neha Goel\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/381082521878683c8eee258b0b59a911\"},\"headline\":\"Java XPathFactory Example\",\"datePublished\":\"2017-11-02T09:00:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/\"},\"wordCount\":525,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"XPathFactory\"],\"articleSection\":[\"XPath\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/\",\"name\":\"Java XPathFactory Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2017-11-02T09:00:45+00:00\",\"description\":\"In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-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\/java-xpathfactory-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\":\"Java XPathFactory 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\/381082521878683c8eee258b0b59a911\",\"name\":\"Neha Goel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Neha-Goel_avatar_1492513971-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Neha-Goel_avatar_1492513971-96x96.jpg\",\"caption\":\"Neha Goel\"},\"description\":\"Neha holds a Bachelors degree in Computer Science and Engineering. Currently she is working as a Sr. Programmer Analyst for a client in USA and has a total of 9+ years of Java\/J2EE experience.Her expertise includes participation in all stages of SDLC. She has experience with multiple web based and enterprise based applications. She has a very impressive understanding in Object oriented architecture, analysis, design and software development using latest technologies like Java, J2EE , Restful Services, Spring, Hibernate, JDBC, JSP, Servlets, GWT, ATG etc.\",\"sameAs\":[\"https:\/\/examples.javacodegeeks.com\/\",\"https:\/\/www.linkedin.com\/in\/neha2508\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/neha-goel\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java XPathFactory Example - Java Code Geeks","description":"In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic","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\/java-xpathfactory-example\/","og_locale":"en_US","og_type":"article","og_title":"Java XPathFactory Example - Java Code Geeks","og_description":"In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-11-02T09:00:45+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":"Neha Goel","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Neha Goel","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/"},"author":{"name":"Neha Goel","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/381082521878683c8eee258b0b59a911"},"headline":"Java XPathFactory Example","datePublished":"2017-11-02T09:00:45+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/"},"wordCount":525,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["XPathFactory"],"articleSection":["XPath"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/","name":"Java XPathFactory Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2017-11-02T09:00:45+00:00","description":"In this example, we will see what is java XPathFactory and its usage with example.\u00a0Before we start with this article, it is expected that we have a basic","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/xml\/xpath\/java-xpathfactory-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\/java-xpathfactory-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":"Java XPathFactory 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\/381082521878683c8eee258b0b59a911","name":"Neha Goel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Neha-Goel_avatar_1492513971-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Neha-Goel_avatar_1492513971-96x96.jpg","caption":"Neha Goel"},"description":"Neha holds a Bachelors degree in Computer Science and Engineering. Currently she is working as a Sr. Programmer Analyst for a client in USA and has a total of 9+ years of Java\/J2EE experience.Her expertise includes participation in all stages of SDLC. She has experience with multiple web based and enterprise based applications. She has a very impressive understanding in Object oriented architecture, analysis, design and software development using latest technologies like Java, J2EE , Restful Services, Spring, Hibernate, JDBC, JSP, Servlets, GWT, ATG etc.","sameAs":["https:\/\/examples.javacodegeeks.com\/","https:\/\/www.linkedin.com\/in\/neha2508"],"url":"https:\/\/examples.javacodegeeks.com\/author\/neha-goel\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/51271","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\/125"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=51271"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/51271\/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=51271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=51271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=51271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}