473,749 Members | 2,411 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extract and process XML data from a string

TXShooter
6 New Member
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 2400
TXShooter
6 New Member
Code tags weren't available for my first post. Sorry.
Jan 3 '13 #2
isaaccw
2 New Member
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
TXShooter
6 New Member
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
isaaccw
2 New Member
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@Contro lByWeb.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.controlbywe b.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
2239
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 of the arraylist are objects of a simple, serializable custom class that allows the recipient listview to reconstruct the dragged listitems. (the contents of the arraylist actually don’t matter…they can be simple integers and the issues in...
4
4134
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. Here'w what the data looks like: 10-1100-120-000-10-10-00-000 I need to change only this portion: 10-1100-120-000-10-10-00-000 Any ideas on how to do this in a query? Thanks. Kevin
1
2675
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>. Whenever I initiated the extraction, first news title is always "MMU Bulletin Board RSS Feed" with the proper bulletin's link stored, but not the correct news title being stored. Necessary info only appears within <itemand </itemwhich consists...
0
5091
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
2269
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 specifc data from the source code , at last save these data in MYSQL tables. Does this work?
0
1179
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, but the number of files is too high to open them all. This should not be done from a server, but from an normal maschine searchin on a network drive. The number of files varies every day and I must rerun this search a few times within the next...
2
1151
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 separated values I am looking for a way to process the string as follows and output a decimal 8,2
2
1635
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 is ÄlprÉd. Need help...
4
5151
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 account number in amongst varied text. How do I extract this data in a SELECT query in the format id number xx 0107364561 2124 OR
1
1214
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 in a Wonderware Historian data server, which I think is based upon MS SQL Server. We often have need to look at some of the data from each database together, but querying and managing the 2 seperate databases is somewhat costly and prone to poor...
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.