Curl Global Community
XML1:XML Data - Printable Version

+- Curl Global Community (https://communities.curl.com)
+-- Forum: Tutorials (https://communities.curl.com/forumdisplay.php?fid=3)
+--- Forum: Public Training (https://communities.curl.com/forumdisplay.php?fid=4)
+---- Forum: Curl Clues (https://communities.curl.com/forumdisplay.php?fid=5)
+---- Thread: XML1:XML Data (/showthread.php?tid=32)



XML1:XML Data - kino - 06-16-2011

Most data can be transformed into XML content. This provides a drive to use XML as a medium for structuring information the Web for the purpose of data exchange between applications. XML structures data using a text-based markup language similar to HTML and is non-proprietary and platform independent. Open standards and the focus on communication and collaboration among people and applications have created and environmnet where XML Web services are becoming a standard platform for application integration in the move to distributed computing on the Internet. From a Curl client perspective, XML information can be obtained from communicating with a Web service over HTTP or using XML over HTTP.



In either case, the data that is queried and obtained is XML. Therefore it is necessary to first concentrate on handling XML data in the Curl client over HTTP. Once these fundamental principles are understood, then we will access XML data via a Web service in a subsequent Curl Cue.


Curl's XML Document Model


Curl's XML Document Model (XDM) provides functionality for processing XML data in Curl: reading, creating, modifying and writing XML documents. XML document contents are represented as a hierarchy of Curl objects which can be accessed using Curl methods and XPath expressions. Once accessed, the contrent can be displayed, transformed, and processed to meet the application functionality


Curl's XDM is accessible through the Curl Web Services Development Kit (WSDK). The WSDK library must be installed and accessed in order to use access its functionality which include SOAP/WSDL support, and an XML document model. If you plan on displaying and manipulating the examples contained within this Curl Cue, there is no need to download the WSDK. However, once you download and run the examples on your local machine, you will need to download the libraray.


You can download the WSDK library from the official WSDK download page by selecting the following link: WSDK Download.


XDM Nodes


The XDM views XML documents as a tree structure of elements embedded within other elements. All elements, their containing text and their attributes can be accessed through the XDM structure. Their contents can be modified, deleted, and new elements can be created. The elements, associated text and attributes are modeled as nodes.


In the WSDK, XDMNodes are represented by XDMElements, XDMAttributes, XDMText, XDMProcessingIstructions.



Displaying the XML DOM Structure


In the first example, we read the XML, store the data as an XDM document, and then display the data using a tree control structure that allows you to visually expand and compress the XML nodes. This method is very useful during development, but not as common in production applications.


Steps: the quickest way to read and view the XML data is to:

1.Import necessary WSDK packages

2.Create an XML Document model (XDMDocument) using the build-xml procedure.

3.Display the stored XML data using XDMTreeControl

In this example we use XML data created directly in the code using the xml-string variable for simplicity.


width='100%' height='550' src='/wiki/samples/generic-example.curl?WSDKSamples/XML/xmldata.curl'



Note that 2 packages need to be imported from the WSDK:

•COM.CURL.WSDK.XML-DOCUMENT-MODEL: this allows us to access XDMDocument

•COM.CURL.WSDK.XML-DISPLAY: this allows us to access XDMTreeControl





In the second example, we query the XML data from a known Url. This scenario is typical of what you would expect from a deployed application where the xml data resides on a company server.


For this example, the XML data is stored in the file sample.xml. It represents an inventory or resources from the Widgets/Gadgets/Curlets section on Curl's Developer Community (www.developers.curl.com).

Code:
curl
Hardware-accelerated rendering is used to show a 3D view of chemical molecules.
http://developers.curl.com/docs/DOC-1060
http://developers.curl.com/demos/molecules/start.curl



curl
This example displays flames by simulating them mathematically, not just by showing a series of precomputed images.
http://developers.curl.com/docs/DOC-1057
http://developers.curl.com/demos/fire/start.curl



curl
The teapot is a classic example of 3D rendering.
http://developers.curl.com/docs/DOC-1059
http://developers.curl.com/demos/teapot/start.curl

Note: the full list code samples can be found here: Widgets/Gadgets/Curlets.


width='100%' height='390' src='/wiki/samples/generic-example.curl?WSDKSamples/XML/xmldata2.curl'





About build-xml: The build-xml function uses the standard Curl SAX parser and has corresponding keyword arguments. The input source can be specified as a Url or a String, as well as text and byte streams.


The XDMTreeControl displays and exact representation of the XML using a tree structure of elements embedded within other elements. If the XML data had multiple levels, the tree control nodes would expand to view all children.


Since the XDM presents stores XML data as a tree structure, it gives us access to the information through a set of objects. This allows us to query relevant information, transform and process the data, and display the requested information to the user. Thus, we can state the the XDM model is needs to be obtained first before any processing can occur. The following Curl Cues will discuss methods of transformation and display.



RE: XML1:XML Data - RobertShiplett - 05-25-2012

Do will have a similar "Clue" page on JSON ?

thanks





RE: XML1:XML Data - hadriya9091 - 01-12-2013

Nice discussion .... Thanks



RE: XML1:XML Data - Leta56 - 10-21-2013

I agree allthis post. I really impressed by it.