Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reference the root node
Message
De
02/04/2013 03:43:16
 
 
À
01/04/2013 22:07:42
Information générale
Forum:
ASP.NET
Catégorie:
XML
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01569682
Message ID:
01569688
Vues:
42
This message has been marked as the solution to the initial question of the thread.
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform