Currently Being Moderated

Transforming XML

VERSION 2

Created on: Jul 9, 2008 11:44 AM by Curl Education - Last Modified:  Jun 16, 2009 9:12 PM by Administrator

Transforming XML

 

 

The last Curl Cue addressed how to access XML data from a server and store the information as an XML document model (XDMNodes). Now the content must be transformed or processed to meet the application functionality. Since the data has already been internalized, all we need to do is:

  • query the relevant information,

  • perform relevant processesing,

  • and diplay the requested information to the user.

 

 

 

 

One of the most common types of display is a grid.  In the first example, we query data and dislay it using a standard <font color="purple">Table</font> and in the second example we will display it using a <font color="purple">RecordGrid</font>.

 

Querying the Data

Once the data is contained within the Curl XML DOM structure, the goal is to extract elements and their associated values by traversing the node tree. This includes element types, element values, and element attributes. Using the WSDK, there are three different ways to obtain this information.  Either by using object methods, XPath expressions, or elaboration. In this Curl Cue, we will focus on using XPath expressions to query relevant content.

 

We will use the same data from the last Curl Cue (XML Data). The following is the <font color="purple">XDMDocument</font> view so that you can recall the structure of the XML.

 

 

Using XPath to Query Data

 

 

All of the nodes in the <font color="purple">XDMDocument</font> can be queried using an XPath expression. Nodes include <font color="purple">XDMElement</font>,<font color="purple">XDMAttribute</font>, <font color="purple">XDMText</font>, and <font color="purple">XDMProcessingInstruction</font>.

 

XPath expressions are used to traverse the nodes in the XML structure and extract elements and their associated values. XPath queries return an <font color="purple">XPathValue</font> which can be one of the following types:

  • XDMNodeSet

  • String

  • double

  • bool

 

 

In our example,  a <font color="purple">XDMNodeSet</font> is first created to gather all Sample nodes.

def items:XDMNodeSet = {model.search Samples/Sample}

 

 

Then, standard XPATH expressions are used to query relevant data.

  • item.search "@xx" returns an attribute value of xx

  • item.search "xx" returns an element value of xx

 

 

For more information regarding XPath, please see XPath Curl Cue: About XPath.

 

Tabular Display

In the first example, we will be extracting data from th displaying relevant XML data in a table. This is an example of transforming the data for presentation.

 

All XPATH queries will return an <font color="purple">XDMNodeSet</font>, therefore we need to convert it to a <font color="purple">String</font> before it is able to be used in the table. For example:

{item.search title}.as-String

 

 

 

Record Display

 

 

In the next example, we are using the XPath to query the title, description and link. The information is stored in a <font color="purple">RecordSet</font> and displayed to the user with a <font color="purple">RecordDisplay</font>. This is an example of transforming the data into a model for further processing. The model data is then transformed for presentation in to a grid display.

 

 

 

For more information about <font color="purple">RecordSet</font>s, please see RecordSets.

Average User Rating
(0 ratings)




There are no comments on this document

More Like This

  • Retrieving data ...

Incoming Links