Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

So far I have been able to figure out how to read the string from other posts here in the forum. What I am having a problem with is how to read child nodes of the same name. I think I am explaining it right?

 

Here is the string response I have to process.

 

<mmReply command="getStations" userData="hello" status="ok">
<contents>
	<stations>
		<station>
			<id>Station 1</id>
			<description>Streamline</description>
			<interface>auto</interface>
			<status>0</status>
		</station>
		<station>
			<id>Station 2</id>
			<description>Streamline</description>
			<interface>auto</interface>
			<status>0</status>
		</station>
		<station>
			<id>Station 3</id>
			<description>Streamline</description>
			<interface>auto</interface>
			<status>0</status>
		</station>
		<station>
			<id>Station 4</id>
			<description>Streamline</description>
			<interface>auto</interface>
			<status>0</status>
		</station>
	</stations>
</contents>
</mmReply>

 

Using the code below I am only able to return the first <station><id></id></station> data. I don't think I am looping through the nodes correctly.

 

My code

 

       Try
           ListBox1.Items.Clear()
           Dim objNode As XmlNode
           Dim objNode1 As XmlNode
           Dim XMLDoc As New XmlDocument
           XMLDoc.LoadXml(strXMLData)

           Dim NodeList As XmlNodeList
           Dim GetContentsNode As XmlNode
           Dim XmlStations As XmlNode
           Dim XmlID As XmlNode

           GetContentsNode = XMLDoc.SelectSingleNode("mmReply[@command='getStations']")
           'NodeList = XMLDoc.SelectNodes("mmReply[@command='getStations']")
           XmlStations = GetContentsNode.SelectSingleNode("contents/stations")
           NodeList = GetContentsNode.SelectNodes("contents/stations/station")
           Dim strNodeElement As String
           Dim strNodeText As String

           'For Each objNode In NodeList
               For Each objNode In XmlStations
               XmlID = GetContentsNode.SelectSingleNode("contents/stations/Station")
               'XmlID = GetContentsNode.SelectSingleNode("contents/stations/Station")
               For Each objNode1 In XmlID
                   strNodeElement = objNode1.Name
                   If strNodeElement.ToLower = "id" Then
                       strNodeText = objNode1.InnerText
                       ListBox1.Items.Add(strNodeText)
                   End If
               Next
           Next

       Catch ex As Exception
           MsgBox(ex.Message)
       End Try

 

You will see lines i have commented out while tying other things.

 

thanks for your help.

 

ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...