Jump to content
Sign in to follow this  
JKI

Generating and Parsing Scalar XML Elements with Attributes

Recommended Posts

One of the trickiest little features of EasyXML is creating scalar elements with attributes. Granted, it's not entirely obvious -- but, don't worry, it's still as easy as creating a cluster :)

 

Before we show you how it's done, let's review some of the EasyXML basics. (If you'd like to skip the review, scroll down to the Scalar Elements with Attributes section, below.)

Scalar Elements

 

Scalar elements can be created from strings, Booleans, numerics, and other scalar LabVIEW data types. For example, here is a scalar numeric:

 

scalar_element.png

 

EasyXML treats clusters and arrays as compound elements (meaning that they have child elements).

Compound Elements

 

Clusters are compound elements with dissimilar child element names:

 

cluster_compound_element.png

 

Arrays are compound elements with the same name:

 

array_compound_element.png

 

Attributes

 

Compound Elements with Attributes

To add attributes to an element, put a cluster named "#attributes" inside a cluster. For example, here is a compound element with attributes:

 

compound_element_with_attributes.png

 

Scalar Elements with Attributes

Now, to add attributes to a scalar element, things get tricky. We have to follow the same process used for creating compound element with attributes, but with a twist: we use only one scalar child element having the same name as the parent cluster.

 

Recall our scalar element:

 

scalar_element.png

 

To add attributes to this scalar element, we have to do the following:

 

1) convert the scalar into a cluster

2) add an "#attributes" cluster

3) add a scalar element with the same name as the parent cluster

 

Here's what that looks like:

 

scalar_element_with_attributes.png

 

List of Scalar Elements with Attributes

You can create multiple same-named scalar elements with attributes in the same way you create a list of normal scalars. Just drop the cluster inside of an array, as shown in the screenhot, below. Make sure that you name the array, since the cluster name will be ignored (since array element names are always ignored by EasyXML).

 

list_of_scalar_elements_with_attributes.png

 

 

Download the Example VI

 

Scalar_Element_with_Attributes_Example.vi (Saved in LabVIEW 7.1)

 

(Note, you'll need to download the EasyXML demo in order to run this example, if you don't already have the demo or full version installed.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

×

Important Information

By using this site, you agree to our Terms of Use.