473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Extract and process XML data from a string

TXShooter
I'm trying to process the returndata from this device:
http://www.controlbyweb.com/support/five-input.html

My code is thus:
Expand|Select|Wrap|Line Numbers
  1. Public Class ControlByWebTester_Form
  2.   Private Sub Read_DAQ()
  3.     Dim tcpClient As New System.Net.Sockets.TcpClient()
  4.     Dim port As Integer
  5.     Dim ipAddr As String = Convert.ToString(IPAddr_TextBox.Text)
  6.  
  7.     Try
  8.       'Connect to DAQ
  9.       port = Convert.ToInt32(IPPort_TextBox.Text)
  10.       tcpClient.Connect(IPAddr_TextBox.Text.ToString(), port)
  11.  
  12.       If tcpClient.Connected Then
  13.  
  14.         Me.Pwr_Picturebox.Image = My.Resources.Red_LED___On
  15.  
  16.         'Create a network stream object
  17.         Dim netStream As NetworkStream = tcpClient.GetStream()
  18.  
  19.         'If we can read and write to the stream then do so
  20.         If netStream.CanWrite And netStream.CanRead Then
  21.  
  22.           'Send the on command to read status of DAQ
  23.           Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("GET /state.xml?noReply=0 HTTP/1.1" & vbCrLf & vbCrLf)
  24.           netStream.Write(sendBytes, 0, sendBytes.Length)
  25.  
  26.           'Get the response from DAQ
  27.           Dim bytes(tcpClient.ReceiveBufferSize) As Byte
  28.           netStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
  29.  
  30.           'Parse the response and update the webrelay state and input text boxes
  31.           Dim returndata As String = Encoding.ASCII.GetString(bytes)
  32.  
  33.           'Parse out the DAQ state
  34.           Dim array1 As Char() = returndata.ToCharArray()
  35.  
  36. Whereas "array1" contains the string returned from the device. However, that string actually contains an XML response, and try as I might, I can't seem to find how to process it AS XML. The following is exactly the data being sent from the device:
  37. "<?xml version="1.0" encoding="utf-8"?>
  38. <datavalues>
  39. <input1state>0</input1state>
  40. <input2state>0</input2state>
  41. <input3state>0</input3state>
  42. <input4state>0</input4state>
  43. <input5state>0</input5state>
  44. <count1>0</count1>
  45. <count2>0</count2>
  46. <count3>0</count3>
  47. <count4>0</count4>
  48. <count5>0</count5>
  49. <powerupflag>1</powerupflag>
  50. </datavalues>"
  51.  
  52. For now, I'm processing the string as follows:
  53.           Dim PictureBoxList() As PictureBox = {In1_Picturebox, In2_Picturebox, In3_Picturebox, In4_Picturebox, In5_Picturebox}
  54.           Dim k As Int16 = 67
  55.           For i = 0 To PictureBoxList.Length - 1
  56.             If array1(k) = "1" Then
  57.               PictureBoxList(i).Image = My.Resources.Green_LED___On
  58.             Else
  59.               PictureBoxList(i).Image = My.Resources.Green_LED___Off
  60.             End If
  61.             k = k + 30
  62.           Next
k is where each of the values reside within the string.


Problem: How do I process it as actual XML Data, and use that to change the state of my pictureboxes?
Jan 2 '13 #1
4 2382
Code tags weren't available for my first post. Sorry.
Jan 3 '13 #2
Hi TXShooter. I actually work for ControlByWeb and saw this post. I want to help where I can. You may want to check out this tutorial: http://msdn.microsoft.com/en-us/libr...(v=vs.95).aspx

Hopefully this will help you troubleshoot your code.
Jan 17 '13 #3
Thanks Isaac. I ended up going about it the 'semi-hard way' on this particular program. For now, this works, but I would LOVE to pick your brain about other aspects of both the DAQ and the Quad-Relay. Is there any way we can get together to discuss?

Expand|Select|Wrap|Line Numbers
  1.  
  2.           'Parse out the DAQ state
  3.           Dim array1 As Char() = returndata.ToCharArray()
  4.           Dim source As Char() = array1
  5.           Dim TextBoxString As String = ""
  6.           Dim DAQDoc As New XmlDocument
  7.           Dim DAQNodes As XmlNodeList
  8.           Dim DAQNode As XmlNode
  9.           DAQDoc.LoadXml(source)
  10.           DAQNodes = DAQDoc.GetElementsByTagName("datavalues")
  11.           Dim in1variable As String = ""
  12.           Dim in2variable As String = ""
  13.           Dim in3variable As String = ""
  14.           Dim in4variable As String = ""
  15.           Dim in5variable As String = ""
  16.           Dim in1value As String = ""
  17.           Dim in2value As String = ""
  18.           Dim in3value As String = ""
  19.           Dim in4value As String = ""
  20.           Dim in5value As String = ""
  21.           Dim inVarArray() As String = {in1variable, in2variable, in3variable, in4variable, in5variable}
  22.           Dim inValArray() As String = {in1value, in2value, in3value, in4value, in5value}
  23.           Dim m As Integer = 0
  24.           For Each DAQNode In DAQNodes
  25.             Dim baseDAQNodes As XmlNodeList
  26.             Dim bFirstInRow As Boolean
  27.             baseDAQNodes = DAQNode.ChildNodes
  28.             bFirstInRow = True
  29.             'Load the varible names and values
  30.             For Each baseDAQNode As XmlNode In baseDAQNodes
  31.               TextBoxString = TextBoxString + (baseDAQNode.Name & ": " & baseDAQNode.InnerText) + vbCr & vbLf
  32.               inVarArray(m) = baseDAQNode.Name
  33.               inValArray(m) = baseDAQNode.InnerText
  34.               m = m + 1
  35.               If m = 5 Then
  36.                 Exit For
  37.               End If
  38.             Next
  39.           Next
Jan 17 '13 #4
That's great to hear that you got it working. Definitely feel free to contact our support team by phone (1-435-590-5999) or email (support@ControlByWeb.com) to help you out with some more specific questions about any of our products.

Also, on our website you can download any of the product manuals to help in answering any questions you might have. The manual for the WebRelay-Quad is located here: www.controlbyweb.com/webrelay-quad/downloads.html

Looking forward to hearing from you.
Jan 17 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Neil West | last post by:
I’m trying to drag & drop listview items between two instances of my app. The actual data that’s passed in DoDragDrop is an arraylist that’s been serialized to a memorystream. The contents...
4
by: kevinSTS | last post by:
Hi. I'm trying to run an update query in ACC97 to update a data string where only part of the data needs to be changed. Since I don't do this often, I cant for the life of me remember how to do it....
1
by: caine | last post by:
I want to extract web data from a news feed page http://everling.nierchi.net/mmubulletins.php. Just want to extract necessary info between open n closing tags of <title>, <categoryand <link>....
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
1
by: maverickx | last post by:
Hi everyone, this is about my one project, i was planning to do like this: Firstly i printed out the source code of one html page on the DOS window, and then use PERL Regular Expression to extract...
0
by: Tequilaman | last post by:
Hi everybody! I want to search some data string of 3 to 11 characters within a hich number of files. tese files are text files with names that are not .txt but .10F etc. All are in one ffolder,...
2
by: cillian | last post by:
Hi would appreciate any help with this Working on a table in which a string value is stored tableA.somestring = a, b, c, d, e, f, g , i, The string only ever contains these 8 comma...
2
by: rajesh0303 | last post by:
I want to extract substring from string and replace them by character. .ex:In "lphrd" , I want to extract and ,and want them to replace be replaced by Ä and É. so, that the result string...
4
code green
by: code green | last post by:
I have a text field called notes in which users have typed almost anything they like. I need to find numeric data randomly inserted in there. So for example there may be a telephone number and an...
1
by: Michael Fuller | last post by:
We are currently searching for a solution to manage data. We have a bunch of laboratory and field analytical data in an Access 2003 database. We also have some plant process data that is recorded...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.