Solved

read XML from local variable in VB.NET

Posted on 2010-11-24
4
820 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
  • 2
4 Comments
 
LVL 74

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 35

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now