LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten XML dynamicially

Solved!
Go to solution

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.

 

JonasWo_0-1732706663578.png

 

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.

0 Kudos
Message 1 of 7
(275 Views)

Check out my ini-handler, it can read and write (almost) any cluster as an ini-file.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 7
(269 Views)

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...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 3 of 7
(268 Views)
Solution
Accepted by topic author JonasWo

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.

Message 4 of 7
(231 Views)

Consider putting your settings into a class instead of a cluster, and saving the class as a binary file.

paul_a_cardinale_0-1732723555527.png

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).

paul_a_cardinale_1-1732723628342.png

Message 5 of 7
(204 Views)

@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.

 

0 Kudos
Message 6 of 7
(163 Views)

@paul_a_cardinale wrote:

Consider putting your settings into a class instead of a cluster, and saving the class as a binary file.

paul_a_cardinale_0-1732723555527.png

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).

paul_a_cardinale_1-1732723628342.png


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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 7
(141 Views)