06-16-2011, 09:59 AM,
(This post was last modified: 06-16-2011, 10:49 AM by kino.)
|
|||||
|
|||||
XML2: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 Table and in the second example we will display it using a RecordGrid. 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 XDMDocument view so that you can recall the structure of the XML. Code: {curl 6.0, 7.0 applet} Using XPath to Query Data All of the nodes in the XDMDocument can be queried using an XPath expression. Nodes include XDMElement,XDMAttribute, XDMText, and XDMProcessingInstruction. XPath expressions are used to traverse the nodes in the XML structure and extract elements and their associated values. XPath queries return an XPathValue which can be one of the following types: •XDMNodeSet •String •double •bool In our example, a XDMNodeSet is first created to gather all Sample nodes. Code: 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 XDMNodeSet, therefore we need to convert it to a String before it is able to be used in the table. For example: Code: {item.search title}.as-String Code: {curl 6.0, 7.0 applet} Record Display In the next example, we are using the XPath to query the title, description and link. The information is stored in a RecordSet and displayed to the user with a RecordDisplay. 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. Code: {curl 6.0, 7.0 applet} |
|||||
« Next Oldest | Next Newest »
|
Messages In This Thread |
XML2:Transforming XML - by kino - 06-16-2011, 09:59 AM
|
Users browsing this thread:
1 Guest(s)
1 Guest(s)