Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Converting Data to and from XML

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

Extensible Markup Language (XML) is a formatting standard that uses tags to describe data. Unlike an HTML tag, an XML tag does not tell a browser how to format a piece of data. Instead, an XML tag identifies a piece of data.

For example, suppose you are a bookseller who sells books on the Web. You want to classify each book in your library by the following criteria:

  • Type of book (fiction or nonfiction)
  • Title
  • Author
  • Publisher
  • Price
  • Genre(s)
  • Synopsis
  • Number of pages

You can create an XML file for each book. The XML file for a book titled Touring Germany's Great Cathedrals would be similar to the following:

<nonfiction>

<Title>Touring Germany's Great Cathedrals</Title>

<Author>Tony Walters</Author>

<Publisher>Douglas Drive Publishing</Publisher>

<PriceUS>$29.99</PriceUS>

<Genre>Travel</Genre>

<Genre>Architecture</Genre>

<Genre>History</Genre>

<Synopsis>This book fully illustrates twelve of Germany's most inspiring cathedrals with full-color photographs, scaled cross-sections, and time lines of their construction.</Synopsis>

<Pages>224</Pages>

</nonfiction>

Similarly, you can classify LabVIEW data by name, value, and type. You can represent a string control for a user name in XML as follows:

<String>

<Name>User Name</Name>

<Value>Reggie Harmon</Value>

</String>

Using XML-Based Data Types

Converting LabVIEW data to XML formats the data so that when you save the data to a file, you easily can identify the value(s), name(s), and type of the data from the tags that describe the data. For example, if you convert an array of temperature values to XML and save that data to a text file, you easily can identify the temperature values by locating the <Value> tag that identifies each temperature.

Use the Flatten To XML function to convert a LabVIEW data type to XML format. The following block diagram generates 100 simulated temperatures, plots the array of temperatures to a chart, converts the array of numbers to the XML format, and writes the XML data to the temperatures.xml file.

.gif">

Use the Unflatten From XML function to convert a data type in the XML format into LabVIEW data. The following block diagram reads the 100 temperatures in the temperatures.xml file and plots the array of temperatures to a chart.

.gif">

Note   Although you can flatten LabVIEW variant data to XML, attempting to unflatten variant data from XML results in an empty LabVIEW variant.

Refer to the labview\examples\file\XMLex.llb for examples of converting to and from the XML format. 

LabVIEW XML Schema

LabVIEW converts data to an established XML schema. Currently, you cannot create customized schemas, and you cannot control how LabVIEW tags each piece of data. Also, you cannot convert entire VIs or functions to XML.

The predefined XML schema that LabVIEW uses is LVXMLSchema.xsd located in the labview\vi.lib\Utility directory.


Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit