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: 

excel to xml to labview

Solved!
Go to solution

I am trying to import data that is written/edited in excel into labview.  I want to store the file as XML and then import it into Labview during the rpgram execution.  Is there a simple way to do this without writing lots of parsing custom code?  Excel does a file save as XML Spreadsheet or save as XML data file, both withe XML file extension names but neither seems to be easily importable into labview.

 

Any ideas?

0 Kudos
Message 1 of 23
(6,001 Views)

Hi,

 

Probably you can start off by looking the the XML examples shipped with LabVIEW. You can view the examples using the NI Example Finder and search for XML. Start off with looking at the Read Data from XML File and Write Data to XML File VIs. Do take note that the XML data needs to follow the LabVIEW XML Schema.

 

For more information about the XML functions in LabVIEW, refer to the help file or the links below. You can see that the conversion is done using flatten and un-flatten functions.

 

http://zone.ni.com/reference/en-XX/help/371361K-01/lvconcepts/converting_data_to_and_from_xml/

 

 

Also, if you require more extensive examples, you can view the link below:

 

http://search.ni.com/nisearch/app/main/p/bot/no/ap/tech/lang/en/pg/1/sn/catnav:ex,n8:4/q/XML/

 

 

Alternatively if you want a simpler plug-in solution, here's a solution from JKI. You can download the evaluation software and try it out.

 

http://sine.ni.com/nips/cds/view/p/lang/en/nid/209021

 

I hope the above information helps. Thank you.

 

Regards,

Alan

 

Applications Engineer | National Instruments
Singapore (65) 6226 5886 | Malaysia (60) 3 7948 2000 | Thailand (66) 2 298 4800
Philippines (63) 2 659 1722 | Vietnam (84) 28 3911 3150 | Indonesia (62) 21 2783 2355
0 Kudos
Message 2 of 23
(5,962 Views)

Is there a rigid requirement to go from Excel to XML to LabVIEW?  If you have the Report Generation Toolbox, you can read Excel (both .xls and .xlsx) files directly into LabVIEW.  Once there, you have the option of writing the (now) LabVIEW data into an XML file using the NI XML Schema.

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

what I have is an excel SS to enter engineering data as a starting point.  What I want to do though is to have an XML file as the datafile that is stored as a part of the program for life cycle sustainment that is read into the Labview program. My challenge is that Excel does not write an XML file based on a labview schema. 

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

@id wrote:

what I have is an excel SS to enter engineering data as a starting point.  What I want to do though is to have an XML file as the datafile that is stored as a part of the program for life cycle sustainment that is read into the Labview program. My challenge is that Excel does not write an XML file based on a labview schema. 


So write a little utility routine that reads the Excel file with LabVIEW, gets the data in the form you want to have it for your program (such as changing the type of the variables from "All Strings", as Excel writes them, to whatever type you want to use them in LabVIEW), and writes this LabVIEW variable to an XML file based on the LabVIEW Schema.  Now your "real" program can read the XML file, do wha it needs to do, and update it as necessary, writing out more XML.

 

I do exactly this, myself.  We use an Excel Workbook as an "Experiment Planner".  Our Experiment consists of multiple "Trials", numbered 1, 2, ..., each of which has perhaps 100 possible parameter settings (many of which stay constant from trial to trial).  I open Excel, read the first row, which contains the names of the LabVIEW variables as Column Headers, then read subsequent rows.  I have routines that parse the data from the row and basically build a (large) LabVIEW Cluster, with one entry per parameter.  I have an Experiment Header File that is an XML file, and I write out the array of these Trial Parameter clusters.

 

As it happens, I'm using GXML (from NI), available on the NI LabVIEW Tools Network, as I like the format of the resulting XML file (and it allows me to "tweak" its functionality a little), but this scheme should also work with the XML tools native to LabVIEW.

 

BS

Message 5 of 23
(5,897 Views)

So it appears that there is no way of importing an Excel SS that has been file/saved as XML Spreadsheet in excel to Labview without undo pain. Sounds like a new idea to put on the idea exchange because this is a pretty usual mode of operation for engineers who are entering data into excel SS's and then wanting to save them as datasets for their labview program in an XML format. 

 

Is ther any way to save an excel SS out to an xml file using the labview schema then?

0 Kudos
Message 6 of 23
(5,760 Views)

 

I cannot seem to add the Labview Schema as a map to excel for some reason.  The *.XSD schema file will not load into the excel map. This is quite odd.

 

 

Create an XML map

You create an XML map by adding an XML schema to a workbook. The schema can be copied from an XML schema file (.xsd), or Excel can try to infer one from an XML data file (.xsd).

  1. Get started by clicking Source in the XML group on the Developer tab.

XML Refresh Data

If you don't see the Developer tab, do the following to display it:

  • In Excel 2013 and Excel 2010:
  1. Click File > Options.
  2. In the pane on the left, click the Customize Ribbon category.
  3. Under Main Tabs, check the Developer box, then click OK.
  • In Excel 2007:
  1. Click the Microsoft Office Button, and then click Excel Options.
  2. In the pane on the left, click the Popular category.
  3. Under Top options for working with Excel, check the Show Developer tab in the Ribbon box, then click OK.

The XML Source task pane appears.

  1. Click XML Maps, and then lick Add.
  2. In the Look in list, click the drive, folder, or Internet location that contains the file you want to open.
  3. Click the file, and then click Open. If you open:
  • An XML schema file, XML creates an XML map based on the XML schema. If the Multiple Roots dialog box appears, choose one of the root nodes defined in the XML schema file.
  • An XML data file, Excel tries to infer the XML schema from the XML data, and then creates an XML map.
  1. Click OK.

The XML map is displayed in the XML Source task pane.

ShowIssue: When I add an XML map to my workbook, a message tells me that the XML schema can't be added t...

0 Kudos
Message 7 of 23
(5,758 Views)

My guess is that the Labview schema has one of these in it. But I do not even get an error when I try to add it, it just doesnt populate it.

 

There are several types of XML schema constructs that Excel doesn't support. The following list details the XML schema constructs that can't be imported into Excel:

<any>    This element allows you to include elements that aren't declared by the schema.

<anyAttribute>    This element allows you to include attributes that aren't declared by the schema.

Recursive structures    A common example of a recursive structure is a hierarchy of employees and managers in which the same XML elements are nested several levels. Excel does not support recursive structures more than one level deep.

Abstract elements    These elements are meant to be declared in the schema, but never used as elements. Abstract elements depend on other elements being substituted for the abstract element.

Substitution groups    These groups allow an element to be swapped wherever another element is referenced. An element indicates it's a member of another element's substitution group through the <substitutionGroup> attribute.

Mixed content    This content is declared by using mixed="true" on a complex type definition. Excel doesn't support the simple content of the complex type but does support the child tags and attributes defined in that complex type.


0 Kudos
Message 8 of 23
(5,755 Views)

We have a few KnowledgeBase articles that discuss XML file types as well as schemas. The links are below. This would be a good place to start.

 

http://ae.natinst.com/public.nsf/webPreview/3E1759E53173D8BD862573D200686E20?OpenDocument

http://ae.natinst.com/public.nsf/webPreview/EA451498B828894886256F67007AE6B9?OpenDocument

0 Kudos
Message 9 of 23
(5,728 Views)

Thx but I cant open the links for some reason.

0 Kudos
Message 10 of 23
(5,726 Views)