I’ll give a short answer, then explain things in a little more detail (though very definitely only a little more detail). It’s up to you which to read. 
Short Answer: You want to use a relative XPath expression, but at the moment you’re using an absolute one.
Longer Answer:
Your code starts the expression with a /
which selects the document root (the parent of the document element, which is the single element wrapping everything else). By starting with the slash, you effectively make the expression absolute (think of it as, relative to the document root).
When followed immediately by another /
to form //
this forms a special syntax which is an abbreviated form of /descendant-or-self::node()/
. So, your //path
is the same as /descendant-or-self::node()/path
, which would match any path
element which is a descendant of, or is itself, the document root element.
But that’s not what you want! To turn an absolute path into a relative one, the task is simple; just make sure that the first character is not a /
. If a path is not absolute then it is relative, but relative to what? That “what” is called the context node, which is what you provide in the second argument to DOMXPath::query()
. (Aside: if you don’t provide a context node to that method, the default context node is the document element.)
So, to ask for path
nodes which are descendants of the context node, you can use [noparse]descendant::path[/noparse]
. There is no first /
, so the path is relative and it asks to look for elements named path
on the descendant
axis (i.e. a child of the context node, or child of a child of a child of a child of a child… of the context node). As an answer then, you should probably start your XPath expression with descendant::path
rather than //path
.
Now, that is all that you really need to know but I’m going to go on a little tangent.
Instead of starting paths with descendant::
you will often see the following: .//
Mostly because it’s shorter and works pretty much the same as the above, so long as you keep the key difference in mind (more on that in a minute). Both the .
and //
there are abbreviations (the latter, you already know about!) with the dot meaning self::node()
. That matches the context node itself (the only node within the self
axis is the context node). When put into use like .//path
, hopefully you will now be able to recognise that that looks for self::node()/descendant-or-self::node()/path
which in English asks for all path
nodes which are descendants of the context node or (importantly) the context node itself if that is a path
element. However, for the sake of conciseness .//
is often used to match descendants of the context node rather than typing out the clunky descendant::
.
Time to stop there, before I get too carried away. (: