How to use / and // in xpath
Difference between / and ///
When / is used at the beginning of a path:
it will define an absolute path to node "a" relative to the root. In this case, it will only find "a" nodes at the root of the XML tree.
When // is used at the beginning of a path:
It will define a path to node "div" anywhere within the XML document. In this case, it will find "div" nodes located at any depth within the XML tree.
These XPath expressions can also be used in the middle of an XPath value to define ancestor-descendant relationships. When / is used in the middle of a path:
Tt will define a path to node "a" that is a direct descendant (ie. a child) of node "div".
When // used in the middle of a path:
It will define a path to node "a" that is any descendant (child node) of node "div".
When we don't know the immediate parent of a child then we can use "." dot
will still find any node, "div", located anywhere within the XML tree. But, the XPath:
will find any node, "div", that is a descendant of the node . " In other words, preceding the "//" expression with a "." tells the XML search engine to execute the search relative to the current node reference.