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: 

Flatten to XML doesn't work for anything

Hi all,

 

I tried to flatten a LV object to XML with the idea to unflatten it on the other end of a UDP connection.

 

The screenshot below shows that it flattens my object to an XML, but it can't unflatten it back to the object.

The faltten to string and unflatten to string work fine by the way. The only reason to go with a structured text string is easier debugging with tools like Wireshark.

Flatten to and from JSON isn't an option, because it doesn't accept my object.

 

The help file doesn't provide any information (or none that I detected) to any caveats when it comes to flatten and unflatten from XML. It says "anything".

 

Please advise whether it is supposed to work (aka it's a bug) or that I'm missing/overlooking a crucial piece of information in the help.

 Flatten to XML issue.PNG

Regards,
André (CLA, CLED)
0 Kudos
Message 1 of 6
(1,929 Views)

It's hard to tell based on a screenshot, but are those Variants inside your classes' private data structure?

 

If so, that's what's causing the problem.  The class constant you pass in has to have the Variant "pre-set" to match the type in the saved class.  Example: 

If you run this code:

Kyle97330_0-1602783028362.png

This is the FP output:

Kyle97330_1-1602783070344.png

However, with a class, this isn't possible.  The "unflatten from XML" node uses the default value of the class, always:

 

This:

Kyle97330_0-1602783448784.png

Outputs this:

Kyle97330_1-1602783472980.png

So the only way to unflatten LabVIEW class XML that has a Variant in it is to not have anything stored inside the Variant...

Message 2 of 6
(1,878 Views)

@Kyle97330 wrote:

It's hard to tell based on a screenshot, but are those Variants inside your classes' private data structure?


It is actually a Map (based on the XML).  That error is usually a version mismatch in the class data (note the Version element), in this case it is not clear why LV perceives a mismatch.  I would try (1) branching the wire you feed to the Flatten function to the Unflatten function to see if the error persists and (2) changing the string indicator with the XML to a control, playing with the Version element value and see if you can get the error to go away.  Again, this just localizes the problem, the root cause may still be a bug.

Message 3 of 6
(1,868 Views)

You are correct. I'm using a variant as the map's value type. To make matter worse: I'm using the variant attributes to create a "map" inside a map.

 

The reason why I'm not using a map instead of the variant attribute method is that it crashes cRIO code. See https://forums.ni.com/t5/LabVIEW/LV-Real-time-crash-on-specific-map-use-with-objects/m-p/4015176. (Bug filed)

 

I will continue to use the regular flatten to and unflatten from string functions to send my object across a network connection.

I was hoping to provide some data insights for the customer in case of problems.

 

 

Regards,
André (CLA, CLED)
0 Kudos
Message 4 of 6
(1,843 Views)

I tried it with an intialized (some fields different values) object attached to the data type input of unflatten from XML, to no avail. It's most certainly the variant causing the issue.

Regards,
André (CLA, CLED)
0 Kudos
Message 5 of 6
(1,839 Views)

Even if this worked (e.g. not give an error), the variant attributes are not part of the variant's value.

 

So even if this did work, flattening\unflattening will not preserve the 'map':

Flattening variant attributes.PNG

0 Kudos
Message 6 of 6
(1,833 Views)