From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflattern in C#: How to parse LV-generated XML in CSharp?

Hello,

 

it is very easy to flattern an object (e.g. my cluster,...) to XML string in LabView!

And it is also very easy to unflattern this XML string back to the object (to my cluster).

 

What I want:

1. Flattern Cluster in LabView to XML string

2. Store in SQL Database

3. Read (Unflattern) in C# Application

 

e.g. my cluster consists of:

1. integer: num1

2. boolean: on

3. array of clusters (bool, int): data1

 

Question: How to unflattern the XML string in C#?

 

Thank you verymuch in advance!

BR

EWiebe

-------------------------------------------------------------------
Eugen Wiebe
Bernstein AG
CLAD - Certified LabView Associate Developer
0 Kudos
Message 1 of 5
(3,321 Views)

I don't know anything about how C# treats XML.  However, if you have the XML file that LabVIEW produces, it is "human-readable", so you can print it out and look at it.  What does C# expect for its XML?  If you don't know, try generating a C# XML file with the same type of data that you used in LabVIEW (using analogous C# constructs).  Print that file out, as well.

If everything were the Best in this Best of All Possible Worlds, the two files would be identical.  I'm going to guess that they'll be different, but (with luck) the differences will be (a) obvious and (b) "editable", that is, you should be able to make a "LabVIEW-to-C# XML Translator" that will transform the LabVIEW XML file to a form that C# can interpret.  Indeed, there may be XML features (analogous to Style Sheets) that will do this for you.

 

Good Luck.

 

BS

0 Kudos
Message 2 of 5
(3,309 Views)

EWiebe wrote:

Question: How to unflattern the XML string in C#?


Probably better to ask this on a C# forum! There are plenty of tools in C# to deserialize XML, although I have no experience with which ones will make it easy to use the LabVIEW schema. Try a Google search for "C# deserialize XML". Microsoft's System.Xml.Serialization library might be a good place to start.

0 Kudos
Message 3 of 5
(3,292 Views)

It is very easy to parse XML in C# - indeed the core library provides several different ways to do it. You do, however, have to some understanding of the elements in your XML or have the schema handy. It sounds as though you do know the elements you are expecting, which should make it a cinch.

 

I recommend LINQ-to-XML for this in C# (assuming you are running framework 3.5 or later). You can load the xml string into an XDocument and then parse using LINQ. This will give you access to all the sophisticated queries that LINQ offers.

 

0 Kudos
Message 4 of 5
(3,277 Views)
Take a look at this. It gives you the LabVIEW schema which may help you:http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/converting_data_to_and_from_xml/
0 Kudos
Message 5 of 5
(3,268 Views)