For demonstration purposes, this article generates an XML file that contains employee data. The EasyXML Toolkit uses Clusters to represents parent or root elements. An element with an assigned value is represented by a String Control.
Follow the steps below, changing the elements and values to match the data to your specific requirements:
1. Launch LabVIEW and navigate to
File >> New VI.
2. Save the new VI to a convenient location on the development PC.
- This example VI has been saved as "EasyXML Create File.vi".
3. Place the
Easy Generate XML VI on the Block Diagram.
- This can be located in the Functions palette from JKI Tools >> EasyXML Toolkit for LabVIEW.
4. On the Front Panel, place a
Cluster.
- Locate this in the Controls palette by going to Data Containers >> Cluster.
- This Cluster represents the root element in the XML file.
- Note: To view the Cluster elements concisely, right-click the Cluster and select AutoSizing >> Arrange Vertically.
5. The below XML structure will be used to demonstrate multi-layer child elements and assigning values to elements:
<sampleXML>
<employeeData>
<employee1>
<ID>1234</ID>
<firstName>James</firstName>
<lastName>Williams</lastName>
<departmentInfo>
<department>Sales</department>
<departmentCode>SD1</departmentCode>
<location>UK</location>
</departmentInfo>
</employee1>
<employee2>
<ID>5678</ID>
<firstName>Anna</firstName>
<lastName>Jones</lastName>
<departmentInfo>
<department>Marketing</department>
<departmentCode>MD1</departmentCode>
<location>Germany</location>
</departmentInfo>
</employee2>
</employeeData>
</sampleXML>
- Using this as a reference point, the root element is represented with a LabVIEW Cluster called "sampleXML".
- "sampleXML" contains a child element called "employeeData", which is defined with a Cluster inside the "sampleXML" Cluster.
- "employeeData" contains two child elements labelled "employee1" and "employee2". Each of these are constructed using a Cluster inside the "employeeData" Cluster.
- "employee1" and "employee2" each contain the following child elements, which are defined using a String Control since these elements require a value:
- "employee1" and "employee2" also consist of another child element, "departmentInfo", which itself contains a series of String Controls that represent elements with values:
- department
- departmentCode
- location
6. The resulting Cluster should now resemble the following image.
- Note that all elements comprising of values are constructed using a String Control where the label defines the element name and the string defines the value.
7. Connect this Cluster to the
LabVIEW Data input of the
Easy Generate XML VI.
- Optionally, to view the resulting XML output, connect an Indicator to the XML String output.
8. To save this data to an XML file:
- Place an Easy Write XML File VI, which can be found in the Functions Palette from JKI Tools >> EasyXML Toolkit For LabVIEW.
- Create a Constant on the XML File Path input. This defines the location to save the XML file.
- Optionally, set the Overwrite File? (false) input to True to avoid creating duplicate copies each time the VI runs.
- Connect the Cluster ("sampleXML" from the example) to the LabVIEW Data input of Easy Generate XML.
- The VI should now resemble the following:
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.