在VB.NET中扫描XML数据条目

时间:2016-02-04 22:17:35

标签: xml vb.net

我有一些XML数据需要检查才能传递给我正在构建的VB .NET表单。

下面的XML文档示例
  <icIntegrationConfiguration>
<icServer hostname="icserver" username="icadmin" password="1234" useNtAuth="false"/>
<lyncFarm ucmaAppId="InteractionCenterLyncIntegrationService" ucmaUserAgent="icUcmaUser" ucmaAppName="InteractionCenterLyncIntegrationService" ucmaVersion="3"/>
 <profiles>
<!-- Enterprise Voice synchronizes only if an Interaction Center client is logged in. -->
  <profile scope="Global" qualifier="EnterpriseVoice">
    <augmentationConfigurations>
      <augmentationConfiguration name="Default" order="1" enableIcToLyncSync="true" enableLyncToIcSync="true" addInQueueText="true">
        <conditions>
          <condition name="UserState">
            <qualifications>
              <qualification argument="LoggedInToClient" value="True"/>
            </qualifications>
          </condition>
          <condition name="UserType">
            <qualifications>
              <qualification argument="EnterpriseVoice" value="True"/>
            </qualifications>
          </condition>
        </conditions>
        <presenceMap>
          <presenceMapping icStatus="Available" lyncPresenceFromIc="3500" direction="TwoWay"/>
          <presenceMapping icStatus="Available, Follow-Me" lyncPresenceFromIc="3500" direction="TwoWay"/>
          <presenceMapping icStatus="Available, Forward" lyncPresenceFromIc="3500" direction="TwoWay"/>
          <presenceMapping icStatus="Available, No ACD" lyncPresenceFromIc="3500" direction="TwoWay"/>

我特别想要提取<presenceMap>属性的数据,但我想分别阅读每一行。当我使用下面的代码读出这个时,我更新了一个标签属性,该属性转储以&#34; presenceMapping icStatus&#34;开头的所有元素。成一个多线标签。这里的最终游戏是能够循环遍历这些线,并确切地确定需要显示什么,但我似乎无法先掌握基本任务。以下是我目前使用的代码。

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles btnLoad.Click

    If (System.IO.File.Exists(txtPath.Text.ToString())) Then

        Dim document As XmlReader = New XmlTextReader(txtPath.Text.ToString())

        While (document.Read())

            Dim type = document.NodeType

            If (type = XmlNodeType.Element) Then

                If (document.Name = "presenceMap") Then

                    xmlLync1.Visible = True
                    xmlLync1.Text = document.ReadInnerXml.ToString()
                End If
            End If

        End While

    Else

        MessageBox.Show("The filename you selected was not found.")

    End If

任何提示都非常赞赏。

1 个答案:

答案 0 :(得分:0)

这是语法试试这个。

Dim Nodes As XmlNodeList = YourXMLDocument.DocumentElement.SelectNodes("/ParentNode/ChildNode")


 For Each node As XmlNode In Nodes 
 If node.Attributes("YourNodeName").Value = Something 
  Do stuff

  End if 
 Next