XML.SQL2XML

Previous Next

Converts SQL syntax to XML format. The SQL statement must be syntactically and semantically correct. If the SQL statement cannot be parsed, for example if tables or columns used in the SQL statement are not defined, an error is given.

Syntax

INVOKE    XML.SQL2XML WITH
SELECT       sql-statement     SQLStatement
,            schema-path       SchemaPath
,            xml-declaration   XmlDeclaration
FROM        ...
 
xml-declaration  := { Yes | No }

All parameter names and values are case-insensitive.

The required sql-statement value is a quoted string which is the SQL statement to be converted to XML. This contrasts with most other implementations in the XML internal component, where unquoted SELECT statements are passed to the main INVOKE statement. Because sql-statement is a quoted string, each single quote (') within the SQL statement must be escaped by two consecutive single quotes: '':

SELECT    'insert into tour( destination, tour_type) values (''AUSTRALIA'',''SUMMER_TRIP'')'   SQLStatement

The optional schema-path value provides a path to an XML schema definition (XSD) file.

If schema-path is specified, its value must be a filepath that leads to a valid schema document, and the "SchemaPath" alias is mandatory.

If schema-path is not specified, no reference to a schema is generated into the XML document.

A schema file with extension .xsd is delivered with the USoft product:

USoft-installation-folder/xsl/ExtendedConditions/SQL2XML.xsd

 

To validate the generated XML against this schema, schema-path must be specified.

If the optional xml-declaration is set to 'Yes' (the default), an XML declaration is included in the result. This XML declaration shows the default Rules Engine encoding. If xml-declaration is specified, the "XMLDeclaration" alias is mandatory. If xml-declaration is 'No', no XML declaration is returned.

 

Example

INVOKE XML.SQL2XML WITH
SELECT
    'SELECT * FROM TOUR' SQLStatement,
    'C:\Program Files\USD70\xsl\ExtendedConditions\SQL2XML.xsd'  SchemaPath

This results in the following XML output:

<?xml version="1.0" encoding="Windows-1252"?>
<SqlNode version="1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation=
        "C:\Program Files\USD70\xsl\ExtendedConditions\SQL2XML.xsd">
<Select>
    <SelectList>
     <SelectListElement position="1">
     <Column name="*" table_name="TOUR" table_info_window_name="Tours" position="1"/>
     </SelectListElement>
    </SelectList>
    <TableList>
     <TableListElement name="TOUR" info_window_name="Tours" position="1"/>
    </TableList>
</Select>
</SqlNode>

A complete description of all SQL syntax elements and how they are converted to XML elements and attributes can be found in:

USoft-installation-folder\Help\SQL2XML.doc