I would say Xpath, here the code snippet I use quite often (partially from
MSDN :-):
Public Function GetValueFromXML(ByVal strXMLSrc As String, ByVal strXPath As
String)
Dim strReturnValue As String
Dim xpcContext As XmlParserContext
Dim xtrReader As XmlTextReader
Dim xpdDoc As XPathDocument
Dim xpnNavigator As XPathNavigator
Dim xpniInterator As XPathNodeIterator
Dim xpeExpression As XPathExpression
Dim intLoopCount As Integer = 0
Dim dblReturnValue As Double
Try
xpcContext = New XmlParserContext(Nothing, Nothing, Nothing,
XmlSpace.None)
xtrReader = New XmlTextReader(strXMLSrc, XmlNodeType.Document,
xpcContext)
xpdDoc = New XPathDocument(xtrReader)
xpnNavigator = xpdDoc.CreateNavigator()
xpeExpression = xpnNavigator.Compile(strXPath)
Select Case xpeExpression.ReturnType
Case XPathResultType.Number
dblReturnValue = xpnNavigator.Evaluate(xpeExpression)
If Not Double.IsNaN(dblReturnValue) Then
strReturnValue = CStr(dblReturnValue)
End If
Case XPathResultType.NodeSet
xpniInterator = xpnNavigator.Select(xpeExpression)
While xpniInterator.MoveNext()
If intLoopCount > 0 Then
strReturnValue = strReturnValue &
strValueSeparator
End If
strReturnValue = strReturnValue &
xpniInterator.Current.Value.ToString
intLoopCount = intLoopCount + 1
End While
Case XPathResultType.Boolean
strReturnValue = xpnNavigator.Evaluate(xpeExpression)
Case XPathResultType.String
strReturnValue = xpnNavigator.Evaluate(xpeExpression)
Case Else
Throw New Exception("Invalid XpathResultType")
End Select
GetValueFromXML = strReturnValue
Catch exException As Exception
GetValueFromXML = ""
End Try
End Function
-----Original Message-----
From: Farhan [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 03, 2002 1:58 PM
To: [EMAIL PROTECTED]
Subject: [DOTNET] What is best way to search XML document?
I want to query XML document, what is a best way to do that?
1. Data Island?
2. XPath?
3. XQuery?
I am new to all those terms so am not sure where to begin.
Thanks,
Farhan
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.