>I have a weird situation when referencing a node from the root node.
>
>This is my GetXmlNodeValue() method:
>
>
> ' Get a XML node value
> ' expC1 Node
> Public Function GetXMLNodeValue(ByVal tcNode As String) As Boolean
>
> ' Reset
> cMessage = ""
> cNodeInnerText = ""
> cNodeInnerXML = ""
>
> ' Select the node
> If oXmlNameSpaceManager Is Nothing Then
> oXmlNode = oXmlDocument.SelectSingleNode(tcNode)
> Else
> oXmlNode = oXmlDocument.SelectSingleNode(tcNode, oXmlNameSpaceManager)
> End If
>
> ' See if we obtained the node
> If oXmlNode Is Nothing Then
> cMessage = oApp.StrTran(cNodeDoesNotExist, "##Node##", tcNode)
> Return False
> End If
>
> Try
> cNodeInnerText = oXmlNode.InnerText
> cNodeInnerXML = oXmlNode.InnerXml
> Catch loError As Exception
> cMessage = loError.Message
> Return False
> End Try
>
> Return True
> End Function
>
>
>This is how I call it:
>
>
> ' Get the model number
> If Not loXml.GetXMLNodeValue("//Root.Node/Model/ModelNumber") Then
> Return False
> End If
>
>
>So, this works as I thought until I discovered something weird today. Basically, someone has added an additional root node. So, the full reference is now:
>
>ThisIsTheAdditionalRootNode/Root.Node/Model/ModelNumber
>
>And, when executing the same code, it does not go in the If Not, thus skip the Return False. I cannot understand why the GetXmlNodeValue() is still able to find the node. Isn't // an indication of the root search? Someone has added a useless root node, so this should fail.
>
>Anyone knows why?
You misinterpret the meaning of '//' in an XPath expression - it does not mean root ('/' does). In your case it would find all occurrences of Root.Node/Model/ModelNumber anywhere in the document. See 'Recursive Descent' here :
http://msdn.microsoft.com/en-gb/library/ms256199.aspx