Solved

read XML from local variable in VB.NET

Posted on 2010-11-24
4
829 Views
Last Modified: 2012-05-10
Hi,

I have a RFID application who connect to a RFID controller and get the tag as they are red by the antennas. Packets is received as bytes and after conversion, the data portion of the packet is XML. I put the result in a string variable. On Quick Watch (Visual Studio), it gives:

"<?xml version='1.0'?>
<Matrics><EventGroup><EventList><Tag event='2' raw='000000000000000000000002' PC='3000' time='4ced7e36' RPL='3'/>
</EventList>
</EventGroup>
</Matrics>

I need to get the tag values from this variable. I've never done any XML before.
I tried:

Dim test As String = ""
Dim Packet As Byte() = Nothing

ReDim Packet(TotalBytes - 1)
Dim j As Integer = 0
For i As Integer = 8 To TotalBytes - 3
      Packet(j) = Data(i)
      j += 1
Next

test = tcpXR450.BytestoString(Packet)

Dim XMLcmd As New XmlDocument
XMLcmd.Load(test)    -----> THIS LINE CRASH with exception: "Illegal characters in path."

How can I get the values from the tag in this XML variable?

thanks for your help
0
Comment
Question by:Dominic34
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 34209140
The Load() method of the XmlDocument class expects a file path as an argument. Use the LoadXml() method instead:

    XMLcmd.LoadXml(test)
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 300 total points
ID: 34209194
test = tcpXR450.BytestoString(Packet)
Dim XMLcmd As New XmlDocument
XMLcmd.LoadXml(test)

Check:
http://www.java2s.com/Code/VB/XML/ConstructXMLdocumentfromString.htm
0
 

Author Comment

by:Dominic34
ID: 34213089
Ok, I changed to LoadXML.

I don't understand the following error I get:
'.', hexadecimal value 0x00, is an invalid character. Line 5, position 1.

Variable in Quick Watch give:
"<Matrics><EventGroup><EventList><Tag event='2' raw='000000000000000000000002' PC='3000' time='4cee87d4' RPL='3'/>
</EventList>
</EventGroup>
</Matrics>

thanks for your help
0
 

Author Comment

by:Dominic34
ID: 34213984
ok, figured it out. My array of bytes had 0x00 filled at the end. I trimmed those NULL caracters by doing a ReDim Preserve of the array, at the correct size, and it works fine now.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 53
VB.net Progress Bar - Maximum Value too large 2 26
ASP.NET (VB) return a record 2 52
Groupbox Control ? 2 29
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question