11-27-2024 05:41 AM
Hello everyone,
I have in my program lots of settings which i all cluster together and flatten as XML. When reinitializing the programm i want to read these settings in again. When nothing changed in the cluster (add/delete a control) then i can use unflatten from XML and load them all in.
But as this programm is used on multiple machines and features are getting added constantly, i have to create this XML from scratch again and again.
So is there a way to dynamicially unflatten the XML, so it takes the controls which are present in the loaded XML and the missing controls it just sets to the standard value?
I tried going the route with flatten to JSON, but this fails as i have e.g VISA Resources in the cluster and i can't flatten them to JSON. I also tried to use the XML Parser VIs, but it did not go really anywhere.
I hope someone can give me either the solution or an idea what the best route would be.
Solved! Go to Solution.
11-27-2024 05:53 AM
Check out my ini-handler, it can read and write (almost) any cluster as an ini-file.
11-27-2024 05:54 AM
Hi Jonas,
@JonasWo wrote:
But as this programm is used on multiple machines and features are getting added constantly, i have to create this XML from scratch again and again.
So you took the "easy, but limited" way and now you hit the limits!
With the default functions from NI you need to know the datastructure (aka cluster) to be imported.
When you don't know that structure you could built your own conversion routine. I often use INI files and a conversion VI, that creates all keys from the cluster elements and another VI to read all the needed keys...
11-27-2024 06:35 AM
If you like JSON, check out JSONText. It has support for basically every data type (just not in readable form for something like classes, although there are extensions for them). It can also work with flattened data that contains more or less fields than your cluster.
11-27-2024 10:08 AM
Consider putting your settings into a class instead of a cluster, and saving the class as a binary file.
Even after you make changes to the class data, you'll still be able to read data from old files (because class data auto mutates).
11-28-2024 12:40 AM - edited 11-28-2024 12:42 AM
@Yamaeda and GerdW
Thanks for the handler! I got to some point of it working, but then realized that @cordm solution instantly worked with my programm. But i will keep the ini-handler in mind.
@cordm
Thanks that worked perfectly. I guess i gave up to early when the built in Json conversion failed.
11-28-2024 04:12 AM - edited 11-28-2024 04:13 AM
@paul_a_cardinale wrote:
Consider putting your settings into a class instead of a cluster, and saving the class as a binary file.
Even after you make changes to the class data, you'll still be able to read data from old files (because class data auto mutates).
Be aware of the potential problem with this. This functionality works through a mutation history that is continually added to your class and stored in a private part of the class, as a binary BLOB. If you frequently edit your class private data structure, this mutation history can grow rather large and sometimes poses problems during building of applications or packed libraries. One of the fixes for such build trouble is to remove the mutation history from the class definition file (there is no built in option for that but there are various posts about which part of the lvclass XML data needs to be removed for that and some VIs which do so through simple text search and edit). With that mutation history removed, this technique will however not work anymore.