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
Solved

read XML from local variable in VB.NET

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

791 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