System.Xml.XmlElement System.Xml.XmlElement
<?xml version="1.0" encoding="utf-8" ?> <CAE> <base> <caedata>John</caedata> <caepolicy>Smith</caepolicy> <basecode>john.smith@xyzmail.com</basecode> </base> <base> <caedata>Suzan</caedata> <caepolicy>Carter</caepolicy> <basecode>suzan.carter@xyzmail.com</basecode> </base> <base> <caedata>Tom</caedata> <caepolicy>Baker</caepolicy> <basecode>tom.baker@xyzmail.com</basecode> </base> </CAE>
Public Class Form1 Dim xmlDoc As New XmlDocument() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If redirect(TextBox1.Text) = True Then MsgBox("completed") Else MsgBox("Failed to complete") End If End Sub Function redirect(ByVal BASE As String) Dim fileLoc As String = "C:\Users\Zack\Desktop\hostfile.txt" Dim CP Dim CD xmlDoc.Load("C:\Users\Zack\Desktop\Contact.xml") Dim xmlContactNodeList As XmlNodeList = xmlDoc.GetElementsByTagName("base") For i = 0 To xmlContactNodeList.Count - 1 If xmlContactNodeList.Item(i).Item("basecode").InnerText = BASE Then CP = xmlContactNodeList.Item(i).Item("caepolicy").ToString CD = xmlContactNodeList.Item(i).Item("caedata").ToString If File.Exists(fileLoc) Then Using w As New System.IO.StreamWriter(fileLoc, True) w.WriteLine(CD & vbCrLf & CP) End Using Return True Exit Function End If End If Next Return False End Function End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)