简体   繁体   中英

Scan XML data entries in VB.NET

I have some XML data which I need to inspect in order to pass through to a VB .NET form I am constructing. Sample of the XML document below

  <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"/>

I specifically want to extract the data for the <presenceMap> attribute, but I want to read through each line individually. When I currently read this out using the following code, I update a label attribute which dumps all of the elements beginning with "presenceMapping icStatus" into a multi lined label. The end game here is to be able to loop through each of these lines and decide exactly what needs to be displayed but I cant seem to get to grips with the basic task first. Below is the code I am using currently.

    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

Any hints greatly appreciated.

Here is the syntax try this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM