it's all about what's called the context node [where you are in the document]
that's where to start the search for the node in the xpath from.
I can understand your point, but that only true beacause the search starts from the root of the document since it's the selected node, so if the selected node isn't the root of the document you have to use or not use the slashes.
//: Recursive descent; searches for the specified element at any depth. When this path operator appears at the start of the pattern, it indicates recursive descent from the root node.
here is an example yo show that you :
Code: Select all
data=
(join`r`n
<?xml version="1.0" encoding="utf-8"?>
<OrderInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OrderedBy>
<UserType>1234</UserType>
<UserID>56789</UserID>
</OrderedBy>
<OrderedBy><OrderedBy>
<UserType>abcd</UserType>
<UserID>abcd</UserID>
</OrderedBy></OrderedBy>
</OrderInfo>
)
o := ComObjCreate("MSXML2.DOMDocument.6.0")
o.async := false
o.loadXML(data)
node:=o.selectSingleNode("//OrderInfo/OrderedBy/UserType")
UserType:=Node.text
MsgBox % UserType
; let's select NOT root node
selectednode := o.selectSingleNode("//OrderInfo/OrderedBy/OrderedBy")
node1 := selectednode.selectSingleNode("UserType")
node2 := selectednode.selectSingleNode("/UserType")
node3 := selectednode.selectSingleNode("//UserType")
node1text:=node1.text
node2text:=node2.text
node3text:=node3.text
MsgBox,, xml, No slashes:"%node1text%"`nOne slashe:"%node2text%"`ntwo slashes:"%node3text%"
but it seems to me that a double slash, or even a single one, is not necessary at the beginning
that's why it is necessary.
by its very placement, the parent tag of everything that follows
by its very placement in what context, for you it's the top node, but you could be operating on any node, a node at the end of the document, there for the very placement of the xpath and the parent tag is the last node [the context node].