Discover XGQL PDF Print E-mail
User Rating: / 0
PoorBest 
Saturday, 12 July 2008
HTML clipboard

I. What XGQL?
XGQL (XML Generator Query Language) is a procedural language that allows according to a formalism to generate XML / turn feeds from Web Services, XML data sources or relational databases. It combines the best of worlds XML and relational using all the features of XPath, XQuery and SQL.

To understand all the possibilities of XGQL, we will conduct a case study rather simple to compare two approaches:
    1. SQL, Java and XSLT
    2. XGQL

II. Case Study
II-A. Background

The company Annu-Artisan manages a directory of sites artisans and a list of their products by category.
The company Annu-Artisan wishes to propose a set of merchants themed applicants production craftsmen already enshrined in its directory. As it has the ability to read and process XML field, each artisan registered must provide a description of its products via an XML.
Example flow to provide

<product>
<label> Hammer </ label>
<description_courte> hammer to smash the cloves </ description_courte>
<description_longue> A magnificent hammer knocking cloves: very useful in the kitchen </ description_longue>
<images>
<img> http://photo.ortho.free.fr/images/outils/marteau.jpg </ img>
<img> http://www.stefatelier.com/catalog/images/marteau.jpg </ img>
</ Images>
<prix> 79 </ price>
<stock> 5 </ stock>
<delai_livraison> 4 </ delai_livraison>
</ product>

To simplify management, data on each product (ID and theme of the product) remain stored in the directory Annu-Artisan, in the table ANNU_PRODUCT; the URL field contains the URL to call to retrieve the XML description of the Product.

IDPRODUITS  IDTHEME  URL
3453 1  http://urlArtisan1/monProduit.xml
892 1  http://urlArtisan2/monProduit.xml
4729 2  http://urlArtisan3/monProduit.xml

All these data must then be standardized in order to generate the different interfaces multiple sites.

 Presentation of treatment flows expected
Figure 1 - Presentation of treatment flows expected

II-B. Approach SQL / JAVA / XSLT
A process is fairly simple to make some servlets agregatrices of different data sources (databases and web-service).

 Treatment of flows with SQL / Java / XSLT

Figure 2 - Treatment of flows with SQL / Java / XSLT
The treatment is done in 4 stages:

Step 1 - the database connection

Connection to the base and recovery information based on a specific theme, with a query like: MAQUERY = "SELECT URL ANNU_PRODUCT FROM WHERE IDTHEME = 1", the URL field representing different addresses of XML to recover, to establish consistency of data.

/ / Initialize
ResultSet result = null;
Statement statement = null;
Connection connect = null;
/ / Connection to the base

try (
     Class.forName (className);
     connect = java.sql.DriverManager.getConnection (url, name, password);
     connect.setAutoCommit (false);

) Catch (Exception e) (
/ / Management except
)

/ / Execution of the request
try (
     connect.createStatement statement = (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
     result = statement.executeQuery (MAQUERY);
) Catch (Exception e) (
/ / Management except
)

/ / Close connection to the database
try (
     connect.close ();
) Catch (Exception e) (
/ / Management except
)

Step 2 - Recovery information

Retrieving information from XML based on integrated data in the database

URL url = new URL (urlFluxXml);
           conn = url.openConnection ();
           conn.connect ();

           data = new DataInputStream (new BufferedInputStream (
                          conn.getInputStream ()));

           while ((data.readLine line = ())! = null) (
             buf.append (line);
           )

           data.close ();

Step 3 - Generation XML
The aggregation can be done with a simple object StringBuffer.
myXMLResult.append (xmlResult);
Step 4 - Standardization of XML processing XSLT

This sheet will XSLT sole purpose of removing superfluous information in the XML based applications. For example, a presentation page rapid product, it will only fields' libelles' and 'short description.

II-C. Production XGQL
Using the API XGQL, it is possible to generate a few lines of script XML standard desired.

Figure 3 - Treatment of flows with XGQL
It is possible to make the treatment very quickly as follows:

<? xml version = "1.0" encoding = "UTF-8"?>

<xgql:root xmlns:xgql="http://www.symeria.com/xgql/">
<products>

<! - Definition of the motion ->
<xgql:var name="select"> SELECT URL ANNU_PRODUCT FROM WHERE IDTHEME = 1 </ xgql: var>

<! - Execution of the request ->
<xgql:execute Name="select">
        
<! - Iteration on the different results ->
<xgql:row>
<xgql:var Name="productUrl">
<xgql:column Name="url" wrap="false"/>
</ Xgql: var>

<! - Recovery of different XML via HTTP protocol ->
<xgql:var Name="product">
<xgql:datasource> $ productUrl </ xgql: datasource>
</ Xgql: var>

<! - Standardization of XML ->
<product>
<xgql:process> document) ($ product / product / label </ xgql: process>
<xgql:process> document) ($ product / product / description_courte </ xgql: process>
</ Product>
</ Xgql: row>

</ Xgql: execute>

</ Products>
</ xgql: root>

The script generates the following results:

<products>
<product>
<label> Hammer </ label>
<description_courte> hammer to smash the cloves </ description_courte>
</ Product>
</ products>
In this example script XGQL, three instructions are particularly important (and practical too!):

<xgql:execute name="select">
                                     <xgql:row> ...</ xgql: row>
</ xgql: execute>

Running an SQL based, and iteration on the different results of the query.

<xgql:datasource> $ productUrl </ xgql: datasource>

Reading data on a local disk on a http or ftp (This is an extension of this language since version 1.5).

<xgql:process> document) ($ product / product / label </ xgql: process>

Interpretation of an expression Xpath or XQuery on a variable XML.

 III. Conclusion
Through this case study, we see the benefits XGQL:
    1. Unification of means of access, modification and processing of XML from relational database or XML data
    2. Generating XML data from relational data
    3. Syntax simple
    4. Maintenance facilitated by a code readable
    5. No need to rebuild the project each change
    6. Reducing the complexity of treatment processing (no code necessary XSLT)
    7. Easily upgradeable
    8. XGQL works equally well on a Web server that mode API for applications, having no Web interfaces

XGQL has several extensions and is incorporated into several distributions:
     * SWAS XGQL: pack comprising Jetty, and HSQLDBD XGQL properly configured and ready for use in server mode
     * Cocoon XGQLGenerator: Generateur Cocoon to file XGQL
     * XGQL: DB2XML: Extended language transforming a relational database to XML database

Step 2 - Recovery information

Retrieving information from XML based on integrated data in the database

URL url = new URL (urlFluxXml);
           conn = url.openConnection ();
           conn.connect ();

           data = new DataInputStream (new BufferedInputStream (
                          conn.getInputStream ()));

           while ((data.readLine line = ())! = null) (
             buf.append (line);
           )

           data.close ();

Step 3 - Generation XML
The aggregation can be done with a simple object StringBuffer.
myXMLResult.append (xmlResult);
Step 4 - Standardization of XML processing XSLT

This sheet will XSLT sole purpose of removing superfluous information in the XML based applications. For example, a presentation page rapid product, it will only fields' libelles' and 'short description.

II-C. Production XGQL
Using the API XGQL, it is possible to generate a few lines of script XML standard desired.
 Treatment of flows with XGQL

Figure 3 - Treatment of flows with XGQL
It is possible to make the treatment very quickly as follows:

<? xml version = "1.0" encoding = "UTF-8"?>

<xgql:root xmlns:xgql="http://www.symeria.com/xgql/">
<products>

<! - Definition of the motion ->
<xgql:var name="select"> SELECT URL ANNU_PRODUCT FROM WHERE IDTHEME = 1 </ xgql: var>

<! - Execution of the request ->
<xgql:execute Name="select">
        
<! - Iteration on the different results ->
<xgql:row>
<xgql:var Name="productUrl">
<xgql:column Name="url" wrap="false"/>
</ Xgql: var>

<! - Recovery of different XML via HTTP protocol ->
<xgql:var Name="product">
<xgql:datasource> $ productUrl </ xgql: datasource>
</ Xgql: var>

<! - Standardization of XML ->
<product>
<xgql:process> document) ($ product / product / label </ xgql: process>
<xgql:process> document) ($ product / product / description_courte </ xgql: process>
</ Product>
</ Xgql: row>

</ Xgql: execute>

</ Products>
</ xgql: root>

The script generates the following results:

<products>
<product>
<label> Hammer </ label>
<description_courte> hammer to smash the cloves </ description_courte>
</ Product>
</ products>
In this example script XGQL, three instructions are particularly important (and practical too!):

<xgql:execute name="select">
                                     <xgql:row> ...</ xgql: row>
</ xgql: execute>

Running an SQL based, and iteration on the different results of the query.

<xgql:datasource> $ productUrl </ xgql: datasource>

Reading data on a local disk on a http or ftp (This is an extension of this language since version 1.5).

<xgql:process> document) ($ product / product / label </ xgql: process>

Interpretation of an expression Xpath or XQuery on a variable XML.

 III. Conclusion
Through this case study, we see the benefits XGQL:
    1. Unification of means of access, modification and processing of XML from relational database or XML data
    2. Generating XML data from relational data
    3. Syntax simple
    4. Maintenance facilitated by a code readable
    5. No need to rebuild the project each change
    6. Reducing the complexity of treatment processing (no code necessary XSLT)
    7. Easily upgradeable
    8. XGQL works equally well on a Web server that mode API for applications, having no Web interfaces

XGQL has several extensions and is incorporated into several distributions:
     * SWAS XGQL: pack comprising Jetty, and HSQLDBD XGQL properly configured and ready for use in server mode
     * Cocoon XGQLGenerator: Generateur Cocoon to file XGQL
     * XGQL: DB2XML: Extended language transforming a relational database to XML database

 
< Prev   Next >
School Joomla Templates and Joomla Tutorials