I am building a tool for my team at work to search a XML file for a particular item and return back the nodes associated with it. I have searched the web to no abounds and was wondering if someone would mind letting me know what I am missing.
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration>
<ServiceName ID="AddNote">
<Client ID="Opera">
<Service>Administration</Service>
<Method>AddNote</Method>
<Version>1.1</Version>
<RetryOption>False</RetryOption>
<qa03queue>Company.Policy.AddNote</qa03queue>
</Client>
</ServiceName>
<ServiceName ID="AuthenticateUser">
<Client ID="Gas Station">
<Service>Enterprise</Service>
<Method>AuthenticateUser</Method>
<Version>1.0</Version>
<RetryOption>False</RetryOption>
<qa03queue>Company.Enterprise.AuthenticateUser</qa03queue>
</Client>
Here is my code... I have a single text box named txtMethod and radio buttons that are selected to help search a node associated with it. Here is what I have...
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim ClientRdo As String
'Radio Button Check on Search
If rdoOpera.Checked = True Then
ClientRdo = "Opera"
ElseIf rdoGasStation.Checked = True Then
ClientRdo = "Gas Station"
Else
MsgBox("You must choose a client to search the file.")
End If
'Search(Document)
Dim xmldoc As New System.Xml.XmlDocument()
Dim xmlnode As System.Xml.XmlNodeList
Dim i As Integer
Dim fs As New System.Xml.XmlTextReader("C:\MyFile.xml")
xmldoc.Load(fs)
xmlnode = xmldoc.GetElementsByTagName("Client")
'This is the text box that I want to search for "AddNote" or Service ID in the XML
Dim Method As String
Method = txtMethod.Text
Do Until fs.EOF
'This should find "AddNote" if it is entered into textbox
xmldoc.SelectSingleNode("//ServiceConfiguration[ServiceName ID='" + Method + "']")
'This should find either "Opera" or "Gas Station" along with the Service Name ID
ClientRdo = xmlnode(i).ParentNode.Item(1).InnerText.Trim()
'It will continue to do this till it is found in the XML file
Loop
'Once found, it will display the results of the children in the remaining textboxes
txtService2.Text = xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
txtMethod2.Text = xmlnode(i).ChildNodes.Item(1).InnerText.Trim()
txtVersion.Text = xmlnode(i).ChildNodes.Item(2).InnerText.Trim()
txtQue.Text = xmlnode(i).ChildNodes.Item(4).InnerText.Trim()
Any help would be greatly appreciated!