05-20-2015 09:52 AM
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
05-20-2015 10:27 AM
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
05-20-2015 12:23 PM
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.
05-20-2015 02:14 PM
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.
05-20-2015 03:17 PM