将富格文本框中的xml文件从远程服务器加载到vb.net表单

将富格文本框中的xml文件从远程服务器加载到vb.net表单,vb.net,Vb.net,我在vb.net中有一个windows应用程序,我正在尝试从服务器读取xml文件(http://dev2010.abc.com/abc.xml).我能读懂abc.xml现在我需要在vb.net的富文本框中显示abc.xml,然后我必须在combobox中显示节点及其值。我可以通过一个目录(假设该文件是C:/abc.xml格式)来实现这一点 请告诉我如何在富文本框中从服务器加载xml文件,然后在组合框中显示节点和相应的值,并在文本框中显示其输出 VB.NET中的代码 Imports System.

我在vb.net中有一个windows应用程序,我正在尝试从服务器读取xml文件(http://dev2010.abc.com/abc.xml).我能读懂abc.xml现在我需要在vb.net的富文本框中显示abc.xml,然后我必须在combobox中显示节点及其值。我可以通过一个目录(假设该文件是C:/abc.xml格式)来实现这一点 请告诉我如何在富文本框中从服务器加载xml文件,然后在组合框中显示节点和相应的值,并在文本框中显示其输出

VB.NET中的代码
Imports System.Xml
导入System.IO
公开课表格1
继承System.Windows.Forms.Form
区域“Windows窗体设计器生成的代码”
公共分新()
MyBase.New()
初始化组件()
端接头
受保护的重载重写子处置(ByVal作为布尔值处置)
如果是这样的话
如果不是(组件什么都不是),那么
components.Dispose()
如果结束
如果结束
MyBase.Dispose(Dispose)
端接头
Friend WithEvents txtFile As System.Windows.Forms.TextBox
Friend WithEvents txtResults As System.Windows.Forms.TextBox
Friend WithEvents BTNL列表为System.Windows.Forms.Button
Friend WithEvents TXT标记名为System.Windows.Forms.TextBox
Friend WithEvents lblFile作为System.Windows.Forms.Label
Friend WithEvents lblTag作为System.Windows.Forms.Label
Friend WithEvents ComboBox 1作为System.Windows.Forms.ComboBox
Friend with Events DG_IPInfo As System.Windows.Forms.DataGridView
私有组件作为System.ComponentModel.Container
私有子初始化组件()
Me.lblTag=New System.Windows.Forms.Label
Me.txtResults=New System.Windows.Forms.TextBox
Me.btnList=新建System.Windows.Forms.Button
Me.lblFile=New System.Windows.Forms.Label
Me.txtFile=New System.Windows.Forms.TextBox
Me.txtTagName=New System.Windows.Forms.TextBox
Me.ComboBox1=新建System.Windows.Forms.ComboBox
Me.DG_IPInfo=New System.Windows.Forms.DataGridView
CType(Me.DG_IPInfo,System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
“lblTag
'
Me.lblTag.Location=新系统.图纸.点(47,30)
Me.lblTag.Name=“lblTag”
Me.lblTag.Size=新系统.图纸.尺寸(32,16)
Me.lblTag.TabIndex=4
Me.lblTag.Text=“标记”
'
“TXT结果
'
Me.txtResults.Location=新系统.图纸.点(496239)
Me.txtResults.Multiline=True
Me.txtResults.Name=“txtResults”
Me.txtdresults.ScrollBars=System.Windows.Forms.ScrollBars.Both
Me.txtResults.Size=新系统.图纸.尺寸(200309)
Me.txtResults.TabIndex=3
'
“btnList
'
Me.btnList.Location=新系统.图纸.点(228,30)
Me.btnList.Name=“btnList”
Me.btnList.Size=新系统.图纸.尺寸(40,23)
Me.btnList.TabIndex=1
Me.btnList.Text=“列表”
'
“伊尔比尔
'
Me.lblFile.Location=新系统.图纸.点(82217)
Me.lblFile.Name=“lblFile”
Me.lblFile.Size=新系统.图纸.尺寸(100,19)
Me.lblFile.TabIndex=5
Me.lblFile.Text=“文件”
Me.lblFile.TextAlign=System.Drawing.ContentAlignment.MiddleCenter
'
'txtFile
'
Me.txtFile.Location=新系统.Drawing.Point(12339)
Me.txtFile.Multiline=True
Me.txtFile.Name=“txtFile”
Me.txtFile.ScrollBars=System.Windows.Forms.ScrollBars.Both
Me.txtFile.Size=新系统.Drawing.Size(224309)
Me.txtFile.TabIndex=2
'
'txtTagName
'
Me.txtTagName.Location=新系统.Drawing.Point(100,30)
Me.txtTagName.Name=“txtTagName”
Me.txtTagName.Size=新系统.Drawing.Size(104,20)
Me.txtTagName.TabIndex=0
Me.txtTagName.Text=“状态”
'
'组合框1
'
Me.ComboBox1.FormattingEnabled=True
Me.ComboBox1.Location=新系统.图纸.点(496179)
Me.ComboBox1.Name=“ComboBox1”
Me.ComboBox1.Size=新系统.图纸.尺寸(200,21)
Me.ComboBox1.TabIndex=6
'
“DG_IPInfo
'
Me.DG_IPInfo.BackgroundColor=System.Drawing.SystemColors.controllight
Me.DG_IPInfo.columnHeadershightSizeMode=System.Windows.Forms.DataGridViewColumnHeadershightSizeMode.AutoSize
Me.DG_IPInfo.Location=新系统图纸点(12,73)
Me.DG_IPInfo.Name=“DG_IPInfo”
Me.DG_IPInfo.Size=新系统图纸尺寸(461127)
Me.DG_IPInfo.TabIndex=7
'
“表格1
'
Me.AutoScaleBaseSize=新系统.图纸.尺寸(5,13)
Me.ClientSize=新系统.Drawing.Size(833560)
Me.Controls.Add(Me.DG_IPInfo)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.txtResults)
Me.Controls.Add(Me.txtTagName)
Me.Controls.Add(Me.lblTag)
Me.Controls.Add(Me.btnList)
Me.Controls.Add(Me.lblFile)
Me.Controls.Add(Me.txtFile)
Me.Name=“Form1”
Me.Text=“GetElementsByTagName”
CType(Me.DG_IPInfo,System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(错误)
我,执行布局
端接头
私有xml_文档作为XmlDocument
私有子表单1_Load(ByVal发送方作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load
Dim解析器作为新的XmlUrlResolver()
将myUri设置为新Uri(“http://dev2010.abc.com/abc.xml")
'将myUri设置为新Uri('http://localhost/test_abc/abc.xml")
'Dim s1 As String=DirectCast(resolver.GetEntity(myUri,Nothing,GetType(String)),String)
Dim s As Stream=DirectCast(resolver.GetEntity(myUri,Nothing,GetType(Stream)),Stream)
将xmlTextReader设置为新的xmlTextReader
Dim xdoc1作为新的XmlDataDocument()
xdoc1.DataSet.ReadXml(xmlTextReader,XmlReadMode.Auto)
Dim ds As DataSet=xdoc1.DataSet
“DG_LiveRates.DataSource=xdoc1.DataSet;
'数据集ds=新数据集();
作为数据表的Dim dt=ds.表(0)
DG_IPInfo.DataSource=dt
Dim文件名为String=DataSubdirectory()&“\abc.xml”
'将结果设置为字符串
Text=GetFileConte
Imports System.Xml
Imports System.IO

Public Class Form1
    Inherits System.Windows.Forms.Form

Region " Windows Form Designer generated code "

Public Sub New()
    MyBase.New()

    InitializeComponent()



End Sub


Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
        If Not (components Is Nothing) Then
            components.Dispose()
        End If
    End If
    MyBase.Dispose(disposing)
End Sub
Friend WithEvents txtFile As System.Windows.Forms.TextBox
Friend WithEvents txtResults As System.Windows.Forms.TextBox
Friend WithEvents btnList As System.Windows.Forms.Button
Friend WithEvents txtTagName As System.Windows.Forms.TextBox
Friend WithEvents lblFile As System.Windows.Forms.Label
Friend WithEvents lblTag As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents DG_IPInfo As System.Windows.Forms.DataGridView

Private components As System.ComponentModel.Container


<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.lblTag = New System.Windows.Forms.Label
    Me.txtResults = New System.Windows.Forms.TextBox
    Me.btnList = New System.Windows.Forms.Button
    Me.lblFile = New System.Windows.Forms.Label
    Me.txtFile = New System.Windows.Forms.TextBox
    Me.txtTagName = New System.Windows.Forms.TextBox
    Me.ComboBox1 = New System.Windows.Forms.ComboBox
    Me.DG_IPInfo = New System.Windows.Forms.DataGridView
    CType(Me.DG_IPInfo, System.ComponentModel.ISupportInitialize).BeginInit()
    Me.SuspendLayout()
    '
    'lblTag
    '
    Me.lblTag.Location = New System.Drawing.Point(47, 30)
    Me.lblTag.Name = "lblTag"
    Me.lblTag.Size = New System.Drawing.Size(32, 16)
    Me.lblTag.TabIndex = 4
    Me.lblTag.Text = "Tag"
    '
    'txtResults
    '
    Me.txtResults.Location = New System.Drawing.Point(496, 239)
    Me.txtResults.Multiline = True
    Me.txtResults.Name = "txtResults"
    Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Both
    Me.txtResults.Size = New System.Drawing.Size(200, 309)
    Me.txtResults.TabIndex = 3
    '
    'btnList
    '
    Me.btnList.Location = New System.Drawing.Point(228, 30)
    Me.btnList.Name = "btnList"
    Me.btnList.Size = New System.Drawing.Size(40, 23)
    Me.btnList.TabIndex = 1
    Me.btnList.Text = "List"
    '
    'lblFile
    '
    Me.lblFile.Location = New System.Drawing.Point(82, 217)
    Me.lblFile.Name = "lblFile"
    Me.lblFile.Size = New System.Drawing.Size(100, 19)
    Me.lblFile.TabIndex = 5
    Me.lblFile.Text = "File"
    Me.lblFile.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'txtFile
    '
    Me.txtFile.Location = New System.Drawing.Point(12, 239)
    Me.txtFile.Multiline = True
    Me.txtFile.Name = "txtFile"
    Me.txtFile.ScrollBars = System.Windows.Forms.ScrollBars.Both
    Me.txtFile.Size = New System.Drawing.Size(224, 309)
    Me.txtFile.TabIndex = 2
    '
    'txtTagName
    '
    Me.txtTagName.Location = New System.Drawing.Point(100, 30)
    Me.txtTagName.Name = "txtTagName"
    Me.txtTagName.Size = New System.Drawing.Size(104, 20)
    Me.txtTagName.TabIndex = 0
    Me.txtTagName.Text = "Status"
    '
    'ComboBox1
    '
    Me.ComboBox1.FormattingEnabled = True
    Me.ComboBox1.Location = New System.Drawing.Point(496, 179)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(200, 21)
    Me.ComboBox1.TabIndex = 6
    '
    'DG_IPInfo
    '
    Me.DG_IPInfo.BackgroundColor = System.Drawing.SystemColors.ControlLightLight
    Me.DG_IPInfo.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
    Me.DG_IPInfo.Location = New System.Drawing.Point(12, 73)
    Me.DG_IPInfo.Name = "DG_IPInfo"
    Me.DG_IPInfo.Size = New System.Drawing.Size(461, 127)
    Me.DG_IPInfo.TabIndex = 7
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(833, 560)
    Me.Controls.Add(Me.DG_IPInfo)
    Me.Controls.Add(Me.ComboBox1)
    Me.Controls.Add(Me.txtResults)
    Me.Controls.Add(Me.txtTagName)
    Me.Controls.Add(Me.lblTag)
    Me.Controls.Add(Me.btnList)
    Me.Controls.Add(Me.lblFile)
    Me.Controls.Add(Me.txtFile)
    Me.Name = "Form1"
    Me.Text = "GetElementsByTagName"
    CType(Me.DG_IPInfo, System.ComponentModel.ISupportInitialize).EndInit()
    Me.ResumeLayout(False)
    Me.PerformLayout()

End Sub



Private xml_doc As XmlDocument


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim resolver As New XmlUrlResolver()
    Dim myUri As New Uri("http://dev2010.abc.com/abc.xml")

   ' Dim myUri As New Uri("http://localhost/test_abc/abc.xml")

    'Dim s1 As String = DirectCast(resolver.GetEntity(myUri, Nothing, GetType(String)), String)

    Dim s As Stream = DirectCast(resolver.GetEntity(myUri, Nothing, GetType(Stream)), Stream)


    Dim xmlTextReader As New XmlTextReader(s)
    Dim xdoc1 As New XmlDataDocument()
    xdoc1.DataSet.ReadXml(xmlTextReader, XmlReadMode.Auto)
    Dim ds As DataSet = xdoc1.DataSet
    'DG_LiveRates.DataSource = xdoc1.DataSet;
    'DataSet ds = new DataSet();
    Dim dt As DataTable = ds.Tables(0)
    DG_IPInfo.DataSource = dt


    Dim file_name As String = DataSubdirectory() & "\abc.xml"

    'Dim results As String

    txtFile.Text = GetFileContents(file_name)

    xml_doc = New XmlDocument()
    xml_doc.Load(file_name)
    ComboBox1.Items.Add("Status")
    ComboBox1.Items.Add("Ip")
    ComboBox1.Items.Add("CountryCode")
    ComboBox1.Items.Add("CountryName")
    ComboBox1.Items.Add("RegionCode")
    ComboBox1.Items.Add("RegionName")
    ComboBox1.Items.Add("City")
    ComboBox1.Items.Add("ZipCode")
    ComboBox1.Items.Add("Latitude")
    ComboBox1.Items.Add("Longitude")


End Sub


Private Sub btnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click
    'Dim xml_node_list As XmlNodeList
    'Dim xml_node As XmlNode
    ' Dim results As String

    'xml_node_list = xml_doc.GetElementsByTagName(txtTagName.Text)


    'For Each xml_node In xml_node_list
    'results = results & xml_node.InnerText & vbCrLf

    'ComboBox1.Items.Add("S")
    'Next xml_node






    'txtResults.Text = results
End Sub


Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    Dim wid As Integer
    Dim hgt As Integer

    wid = ClientSize.Width \ 2
    hgt = ClientSize.Height - txtFile.Location.Y
    If hgt < 10 Then hgt = 10
    lblFile.SetBounds(0, 0, wid, lblFile.Size.Height)
    txtFile.SetBounds(0, txtFile.Location.Y, wid, hgt)

    lblTag.SetBounds(wid, 0, lblTag.Size.Width, lblTag.Size.Height)
    txtResults.SetBounds(wid, txtFile.Location.Y, wid, hgt)
    btnList.SetBounds(ClientSize.Width - btnList.Size.Width, 0, btnList.Size.Width, btnList.Size.Height)
    wid = btnList.Location.X - lblTag.Location.X - lblTag.Size.Width - 10
    If wid < 10 Then wid = 10
    txtTagName.SetBounds(lblTag.Location.X + lblTag.Size.Width, 0, wid, txtTagName.Size.Height)
End Sub

Private Sub txtFile_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFile.TextChanged

End Sub

Private Sub txtResults_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtResults.TextChanged

End Sub

Private Sub txtTagName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTagName.TextChanged

End Sub



Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
    Dim xml_node_list As XmlNodeList
    Dim xml_node As XmlNode
    Dim results As String

    xml_node_list = xml_doc.GetElementsByTagName(txtTagName.Text)


    For Each xml_node In xml_node_list
        results = results & xml_node.InnerText & vbCrLf


    Next xml_node






    txtResults.Text = results
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    Dim xml_node_list As XmlNodeList
    Dim xml_node As XmlNode
    Dim results1 As String
    Dim results As String
    results1 = ComboBox1.Text
    xml_node_list = xml_doc.GetElementsByTagName(results1)


    For Each xml_node In xml_node_list
        results = results & xml_node.InnerText & vbCrLf

    Next xml_node






    txtResults.Text = results


End Sub

Private Sub DG_IPInfo_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DG_IPInfo.CellContentClick

End Sub

Private Sub lblFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblFile.Click

End Sub
End Class