JKI Discussion Forums
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Generating and Parsing Scalar XML Elements with Attributes

#1
User is offline   JKI 

  • Group: JKI Team
  • Posts: 201
  • Joined: 10-July 06
  • Gender:Male
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:

Attached Image: monthly_04_2008/post-7-1208021497.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:

Attached Image: monthly_04_2008/post-7-1208021049.png

Arrays are compound elements with the same name:

Attached Image: monthly_04_2008/post-7-1208020492.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:

Attached Image: monthly_04_2008/post-7-1208020804.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:

Attached Image: monthly_04_2008/post-7-1208021497.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:

Attached Image: monthly_04_2008/post-7-1208021364.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).

Attached Image: monthly_04_2008/post-7-1209494088.png


Download the Example VI

Attached File  Scalar_Element_with_Attributes_Example.vi (62.24K)
Number of downloads: 189 (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.)
0 kudos

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic