ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cluster and Read Write XML

In my applications I allow users to save their settings. I used to do this in a Ini file. So I wrote a Vi that could write any cluster and it worked ok. When I discovered that in the newer versions of LabVIEW you could Read/Write From/To xml, I changed inmediatly because it have some advantages form me but I am having some trouble.

Every time I want to save a cluster I have to use
Flatten To XML -> Escape XML -> Write XML
and to load
Load From XML -> Unescape XML -> Unflatten from XML.

I also do other important things each time I save or load settings. So it seems to be reasonable to put all this in just two subvi's. (One for loading, One for saving). The problem is that I want to use it with any cluster
What I want with can be summarized as following:
- SaveSettings.vi
--Inputs:
---Filename
---AnyCluster
---Error In
--Outputs
---Error Out

-LoadSettings.vi
Inputs:
---Filename
---AnyCluster
---Error In
Outputs
---DataFromXML
---Error Out

I have tried using variants or references and I was not able to make generic sub vi (sub vi that don't know what is in the cluster). I don't want to use a polymorphic vi because it will demand making one load/save pair per each type of settings.


Thanks,

Hernan
0 Kudos
Message 1 of 5
(3,810 Views)
Use the OpenG version of Flatten to XML. It can handle variants.

Check out this thread.
0 Kudos
Message 2 of 5
(3,806 Views)
If I am correct you still you need to wire the data type to the Variant To Data. How can you put in a subvi ALL that is needed to handle the read/write of the cluster? I don't want to put any Flatten To XML or Unflatten From XML outside.

The solution I came out with INI files was passing a reference to a cluster control but it is real unconfortable because I have to itereate through all items.

When a control has a "Anything" input, is there any way to wire that input to a control and remains "Anything"?

Thanks

Hernan
0 Kudos
Message 3 of 5
(3,796 Views)
Did it!

The answer was just in front of my eyes. I wire a property node to get Value (which is a variant when you are using a generic cluster) and using OpengG Flatten To XML and Unflatten from XML I got the job done.

Hernan
0 Kudos
Message 4 of 5
(3,787 Views)
0 Kudos
Message 5 of 5
(3,782 Views)