Simple XML Generation Reference Library

Publish Date: May 06, 2010 | 15 Ratings | 2.07 out of 5 | Print | 2 Customer Reviews | Submit your review

Overview

LabVIEW 8.6 provides a core API for generating and reading XML documents through Property and Method Nodes.  This API requires an intimate knowledge of the DOM (Document Object Model) and can be cumbersome for developers who lack that knowledge.  The Simple XML API component provides high-level functions that vastly simplify the creation of tags, as well as functions that save XML text in a human-readable format.

Table of Contents

  1. The Simple XML Component
  2. Coding Style Recommendations
  3. Discussion and Feedback

1. The Simple XML Component

The Simple XML component installs a new library into the <user.lib> folder, called Simple XML.lvlib. This library contains all the API VIs and polymorphic instance VIs belonging to the component. The API VIs can be placed on the diagram from the Simple XML palette in the User Libraries function palette.

Simple XML function palette

The Simple XML palette contains two rows of VIs. The top row consists of the Simple XML API VIs.  The bottom row contains links to VIs in the core LabVIEW XML API. These VIs are labeled with their library name (NI_XML) to distinguish them from Simple XML VIs. They are provided for convenience, to avoid having to switch back and forth between two palettes while writing code.

The component also installs an example VI into the Example Finder. (See below.)

Simple XML VIs

Simple XML.lvlib contains the following API functions:

Create Tag.vi is the sole VI used to create any type of simple tag in an XML document. It has three polymorphic instances: Create Root, Create Child, and Create Text Child.  The reference output from any of the instances is used to add child tags to this tag, and it must be closed using the NI_XML:Close VI. (See the installed example and the coding style recommendations below.)

Convert to Pretty Print.vi takes the default XML string and adds whitespace characters (tab and newline) to make it human readable.  An example is shown below.

(A)

(B)

An XML document saved using (A) the core XML API, and (B) the Simple XML API

This VI parses through an XML string using a state machine design. The machine has only two states: "Get Starting Bracket" and "Get Ending Bracket". These states are used to increment and decrement the tab-spacing of a given line, based on whether an XML tag is being opened or closed. Every XML tag is placed on a separate line. When a new tag is opened, an extra tab space is added to the previous spacing. When a tag is closed, a tab space is removed. The result is a well-formed XML document that is legible to a human reader.

Save Pretty Print.vi is used to save a "pretty" XML string to file, since the core API's save function does not allow a string to be input manually.

Installed Examples

An updated version of the example Write Test Data File.vi is installed by this component.  The new example, named Write Test Data File - Simple.vi, carries out the same function using the Simple XML API.

To open it using the NI Example Finder, select "Browse by Directory Structure" and navigate to the xml folder. It can also be found at the installation path <lvdir>/examples/xml.

Back to Top

2. Coding Style Recommendations

Because a unique reference wire is created for each tag, keeping the block diagram clean can quickly become difficult when using the Simple XML API.  Here are two options for a sustainable coding style.

Object-Oriented Style

One common style is to take an object-oriented approach to the code.  Each reference created points to an object, and all operations carried out on that object are grouped together.  This results in block diagram that spatially mimics the structure of the XML tree being generated

Object-oriented coding style

Inline Style

Another common coding style requires that all VIs be placed in a line, with the error wire remaining straight at all times. This style makes it easy to see the order of operations in a VI. Under this circumstance, it is recommended that the reference wires be bent upward and run in parallel above the VIs to minimize confusion.

Inline coding style

It is also strongly recommended that subVIs be used to show branch hierarchy in the XML document.  For an example of this method of design, see the CLIP XML Generator's XML Generation module.

Back to Top

3. Discussion and Feedback

This component was created by the NI Systems Engineering group.

We welcome discussion and feedback about this component. The Simple XML Library thread is available on the NI Discussion Forums for questions, comments, and suggestions.

 

Back to Top

Customer Reviews
2 Reviews | Submit your review

A VI Package version of this library  - Jul 22, 2016

You can find a VI Package version of this library on the LabVIEW Tools Network. It can be used with LabVIEW 2013 and later.

Comment on the Simple XML Library thread as well  - Oct 17, 2008

Make sure you comment on the the Simple XML Library thread http://forums.ni.com/ni/board/message?board.id=Components&thread.id=61 as well. Comments posted there will be read and responded to.

Bookmark & Share


Downloads

Attachments:

simple_xml_1_0_0.zip

Requirements


Ratings

Rate this document

Answered Your Question?
Yes No

Submit