Solved

read XML from local variable in VB.NET

Posted on 2010-11-24
4
834 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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