如何通过vb.net中的服务器验证xml

问题描述:

hi

我有一个带有服务器块的xml文件我希望在客户端检查应用程序,数据xml文件服务器匹配。

i have a xml file with blocks in server i want check app in client with data xml file server is match.

在主机目录上有用户和密码需要来自应用程序的凭证来获取和检查信息。

on host directory have user and password need credential from app to get and check info.

    Sub validation()
        Dim url As String = "http://example.com/UserID.xml"
        Dim credentials As New NetworkCredential("user", "pass")
        Using client As New WebClient()
            client.Credentials = credentials
            Using reader As New StreamReader(client.OpenRead(url))
                Dim xe As XElement = XElement.Load(reader)
                For Each info As XElement In xe.Elements
                    Dim id As String = info.<id>.Value
                    If txtSystem.Text = id Then
                        lblValid.Text = "Validate"
                    Else
                        lblValid.Text = "Invalid"
                    End If
                Next
            End Using
        End Using

    End Sub

xml示例:

<?xml version="1.0" encoding="UTF-8"?>
<UID>

<info>
<id>BFEBFBFF000306A2</id>
</info>
<info>
<id>BFEBFBFF000306A9</id>
</info>
<info>
<id>BFEBFBFF000306A1</id>
</info>

</UID>

您正在循环遍历多个< id>元素,但只有一个输出标签,所以你只能看到最后一个< id>的结果。 。元素&NBSP;也许您应该将比较结果添加到ListBox或TextBox中的行。

You are looping through multiple <id> elements, but only have one output label, so you will only see the result of the last <id> element.  Perhaps you should add the result of your comparison to a ListBox or as lines in a TextBox.

您还需要将源代码从网站加载到XDocument并获取根元素开始循环:

You also need to load the source from the website into an XDocument and get the root element before you start the loop:

Dim xe As XElement = XDocument.Load(reader).Root