LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

transfer tree control to subprogram as XML

I've been pretty happy with the labview tree control except that there doensn't seem to be a method for transferring a complete tree from one vi to another. I finally wrote some functions for converting a tree to/from an xml string. To convert to xml, pass the tree refnum to the subvi and out comes xml. To convert back to a new tree, pass a refnum for a new tree and the xml string. I haven't done any optimization for speed or flexibility, (no documentation yet either) but it works pretty well. The attached code has everything you need - I hope someone else will find this useful. I'd love feedback if anyone tries it.

thanks,
George
Message 1 of 23
(5,666 Views)
Very useful!
0 Kudos
Message 2 of 23
(5,434 Views)

Cool. Thanks

0 Kudos
Message 3 of 23
(5,121 Views)

It works fine, thank you very much George.  Smiley Happy

0 Kudos
Message 4 of 23
(5,071 Views)

There is a flat array structure that the tree control uses. The advantage of using this format is that there is no conversion required. We use this flat structure because updates on very large trees (+2000 elements) is very slow when updating via the native methods. Updates on the array are very fast and then you simply write the entire array to the tree control.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 5 of 23
(5,064 Views)

Mark,

 

How do you get access to this flattened structure?

0 Kudos
Message 6 of 23
(4,795 Views)

@JordanMcBain wrote:

Mark,

 

How do you get access to this flattened structure?


Unfortunately there is no way to read it from the tree. You can only set it. You can build the array of clusters your self and set the tree to that value. Use the invoke node with the method "Add multiple items to end". We created a LVOOP tree class and we maintain the data in both the tree and the flattened structure. Changing the value of the tree is accomplished by emptying the tree and then pushing the updataed flattened structure to it.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 7 of 23
(4,781 Views)

Dear gharris!

I'm looking for the solution for writing back a tree structure into XML file. I made a VI to present an XML-file as a tree, but it seems to me rather complicated to write it back. Perhaps I haven't yet a propert algorithm to do it. I was very glad to find your VIs and treid them, but:

- obviosly you use another form of a tree (my tree has another RefType, though they look the same - I converted my by means of "cast")

- the result wasn't a real XML file - as least not as LV "load" functon it "understands

Please have a look at my XML -file, its presentation as tree done by my VI and your result string - you will see, that in your strin are much more special information as it should be in an XML -file. If you have some ideas how to solve this problem (converting tree into XML string/file) I would be very thankfull to you - just now I have no more ideas how to do it .-(.

Smiley Sad

Please find attached 2 pictures of tree presentation and the original XML file

Download All
0 Kudos
Message 8 of 23
(4,471 Views)

Hi Pericles,

What type of tree are you using?  I built this with the labview tree.  Are you using .net or activeX?   I wrote this with labview 7, so maybe its just out of date?  

What error do you get from the xml load.vi?  I wonder if my xml file is just missing some header information.  Take a look at the example for the load.vi, it has an XML example file "TestConfiguration.xml" that starts with some encoding information.  You could try copy/pasting that into your xml file to see if the load.vi will work correctly.

 

I'm not sure what you mean by "much more special information".   Do you mean it is recording too many columns?  In the labview tree there is a property "NumCols" that reports the number of visible columns.  If all your information is shown in visible columns, then you could use this property to limit the number of columns encoded in the xml file.  If you have some code to share, I'd be happy to take a look at it.

 

thanks,

George

0 Kudos
Message 9 of 23
(4,442 Views)

Hi, George,

thank you for your answer. I use LabView tree and work with LabView 2013, maybe the tree itself is not uptodate, but after casting it works, I suppose, that it is just the XML string which you expect to get. I made an XML -display VI using LabView tools from the corresponding library - they are going from node to node getting names and attributes. As a result a tree with 2 columns is displayed. I can send you this VI to have a look at it.

I found and loaded TestConfiguration.xml, it can be also displayed with my VI, though it uses XSD - my original file doesn't have any XSD, that#s why it may be differen in your solution and in what I have to do.

I took my tree, "casted" it to your ref and than used "LoadXML" from the XML palett of LabView. I got the parsing error "Line 2, Column 2,  Message: Expected an element name", maybe that means, that some header info is not correct.

As I see from you VI you convert the tree to an XML- string, and then you can save this string in a file, right? I thought of creating an XML -structure with nodes and attributes just from the tree, but obviously it is a very complicated way, isn't it? My problem is to save changes, which a user has done editing the Tree - it seems to be the simplest way to write donw the TREE  completely in an XML file, because the tree has all the info.  But maybe this way can#t be gone at all :-(.

Please find attached the VI to display an XML file in a tree with 2 columns. I used this display form as an XML Notepad 2007 does it.

Thanks

 

Download All
0 Kudos
Message 10 of 23
(4,438 Views)