Generate a XML structure with the definition given through the argument xmltags and the values obtained from:
- select (or union) in XSQL.
- select in SQL native indicated between the tags nativesql.
- vtable.
- A xml of a sqlresponse.
1 sql.toXML
<sql.toXML
row-name='row-name'
rowset-name='rowset-name'
soap='soap'
localize='localize'
lang='lang'
country='country'
variant='variant'
encoding='encoding'
row-numbering='row-numbering'
mark-nulls='mark-nulls'
>
<union /> ?
<select /> ?
<nativesql /> ?
<xmltags> !
<xmltag
column='column'
tagname='tagname'
format='format'
/> +
</xmltags>
</sql.toXML>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Arow-name | string | Name of the root tag. By default, if this attribute is not introduced, the name of the root tag will be 'row'. | |||
Arowset-name | string | ||||
Asoap | boolean | ||||
Alocalize | boolean | ||||
Alang | string | ||||
Acountry | string | ||||
Avariant | string | ||||
Aencoding | string | ||||
Arow-numbering | boolean | False | Shows the attribute "num" inside the root tag of the generated XML structure. By default it will not be shown. | ||
Amark-nulls | boolean | False | Shows the attribute "null='true'" inside of the tags with null content. By default it will not be shown. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Eunion | null | Query union in xsql. | |||
Eselect | null | Query select in xsql. | |||
Enativesql | null | Query select in native. | |||
Exmltags | null | Allows to define the name of the XML labels. This tag must be the last inside of the function sql.toXML. | |||
Exmltag | null | ||||
Acolumn | string | Name of the column to which the tag refers. | |||
Atagname | string | Name which will appear in the tag. | |||
Aformat | string | Obtains the desired format for the value of the tag. |
Returns | |
---|---|
Type | Description |
string | Returns a table in HTML format with the data obtained of the indicated SQL query. |
Exceptions
input/output exception ...
Input/output fail in the database connection.
sql exception ...
Error of sql.
required attribute '[atributo]' not defined
There is not the required attribute.
Remarks
It is recommended that the xmltag and the columns must match in number, name and order. In this way you can avoid undesired results.
When passing a column of 'date' type, the result obtained may not match with the introduced date.
This fact is done for the serialization in XML, which takes into account GMT timeZone. To avoid this change of date to the time zone, you should give format to the date with the attribute format. The attribute used in XML for a datetime is: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'.
Iy you want that the date appears in year-month-hour, you should choise format='yyyy-MM-dd'.
Query sql through witing on tags.
<xsql-script name='sql_sql2xml1'><body> <println> <sql.toXML> <select> <columns>cdiary.*</columns> <from table='cdiary' /> </select> <xmltags> <xmltag column='code' tagname='CODE' /> <xmltag column='namdia' tagname='DESCRIPTION' /> </xmltags> </sql.toXML> </println> <!-- Another option is to use the tag nativesql to write the sentence in native SQL. --> <println> <sql.toXML> <nativesql>SELECT * FROM cdiary</nativesql> <xmltags> <xmltag column='code' tagname='CODE' /> <xmltag column='nomdia' tagname='DESCRIPTION' /> </xmltags> </sql.toXML> </println> </body> </xsql-script>
It is obtained the structure:
<row> <CODE>DC</CODE> <DESCRIPTION>DIARY OF CASH</DESCRIPTION> </row> <row> <CODE>DV</CODE> <DESCRIPTION>DIARY OF SALES</DESCRIPTION> </row> <row> <CODE>DG</CODE> <DESCRIPCION>GENERAL DIARY</DESCRIPTION> </row>
Query sql through writing on tags.
<xsql-script name='sql_sql2xml2'> <body><sql.toXML row-name='Header' > <select> <columns> 'Hello. This is the content of a tag' <alias name='Salute'/>, <today /> <alias name='dateC' />, deleve </columns> <from table='gdataemp' /> </select> <xmltags> <xmltag column='Salute' tagname='Slts'/> <xmltag column='dateC' tagname='DateCreated' format='yyyy-MM-dd' /> <xmltag column='deleve' tagname='Delegation'/> </xmltags> </sql.toXML> </body> </xsql-script>
Generates:
<Header> <saludo>Hello. This is the content of a tag</salute> <datec>2008-04-28</datec> <deleve>D01</deleve> </Header>
Creation of a XML structure through a vtable.
<xsql-script name='sql_sql2xml3'> <body> <vtable name='v1'> <column name='code' type='char' unique='true' /> <column name='name' type='char' size='25' /> <column name='number' type='integer' /> <column name='balance' type='decimal' scale='2' editable='true' /> </vtable> <vtable.insert name='v1'> <column name='code'>A</column> <column name='name'>Nombre AA</column> <column name='number'>0</column> <column name='balance'>12.9</column> </vtable.insert> <vtable.insert name='v1'> <column name='code'>B</column> <column name='name'>Nombre BB</column> <column name='number'>1</column> <column name='balance'>-17.99</column> </vtable.insert> <sql.toXML row-name='Header' > <in> <v1/> </in> <xmltags> <xmltag column='code' tagname='code'/> <xmltag column='balance' tagname='balance' /> </xmltags> </sql.toXML> </body> </xsql-script>
Creation of a XML structure through a soap-sqlresponse.
<xsql-script name='sql_sql2xml4'> <body> <set name='m_soap_sql_response'> <soap.call url='http://localhost:80/soap/servlet/rpcrouter' uri='urn:SOAPSQLServer' method='executeSQL' user='demo' password='abcdemo' > <parameters> <parameter name='database'>demo_sports1</parameter> <parameter name='sqlstmt'>SELECT * FROM cdiary</parameter> </parameters> </soap.call> </set> <println> <m_soap_sql_response /> </println> <!--The SOAP XML response is the following: <sqlresponse date="2008-04-29T08:25:09.640Z" dbms="demo_sports" host="pluton"> <sqlinfo> <stdout/> <stderr/> <sqlstmt>< ![CDATA[SELECT * FROM cdiary]] ></sqlstmt> <sqluser>demo</sqluser> <sqldbms>demo_sports</sqldbms> <sqllang>es-</sqllang> <sqltype>SELECT</sqltype> <sqltime>0</sqltime> <sqlrows>0</sqlrows> <sqlserial>0</sqlserial> </sqlinfo> <metadata> <column catalogName="" columnClassName="java.lang.String" columnDisplaySize="2" columnLabel="codigo" columnName="codigo" columnType="1" columnTypeName="char" isAutoIncrement="false" isCaseSensitive="false" isCurrency="false" isDefinitelyWritable="true" isNullable="0" isReadOnly="false" isSigned="false" isWritable="true" precision="0" scale="0" schemaName="" tableName="cdiarios"/> <column catalogName="" columnClassName="java.lang.String" columnDisplaySize="40" columnLabel="nomdia" columnName="nomdia" columnType="1" columnTypeName="char" isAutoIncrement="false" isCaseSensitive="false" isCurrency="false" isDefinitelyWritable="true" isNullable="1" isReadOnly="false" isSigned="false" isWritable="true" precision="0" scale="0" schemaName="" tableName="cdiarios"/> </metadata> <rowset encoding="UTF-8" lang="es-"> <row num="1"> <code>CD</code> <nomdia>CASH DIARY</nomdia> </row> <row num="2"> <code>SD</code> <nomdia>SALES DIARY</nomdia> </row> <row num="3"> <code>GD</code> <nomdia>GENERAL DIARY</nomdia> </row> <row num="4"> <code>SD</code> <nomdia>SETTLEMENT DIARY</nomdia> </row> <row num="5"> <code>CA</code> <nomdia>CASH</nomdia> </row> <row num="6"> <code>AM</code> <nomdia>ADMINISTRATION</nomdia> </row> <row num="7"> <code>01</code> <nomdia>01 TEST</nomdia> </row> <row num="8"> <code>00</code> <nomdia>00 TEST</nomdia> </row> </rowset> </sqlresponse> --> <sql.toXML row-name='Header' > <in> <m_soap_sql_response/> </in> <xmltags> <xmltag column='code' tagname='code'/> <xmltag column='nomdia' tagname='name-diary' /> </xmltags> </sql.toXML> </body> </xsql-script>
Shows on screen the result of a query in a XML structure.
<xsql-script name = 'return_xml'> <body> <set name = 'm_xml'> <xml.diary> <sql.toXML row-name = 'diary'> <select> <columns>cdiary.*</columns> <from table='cdiary' /> </select> <xmltags> <xmltag column='code' tagname='CODE' /> <xmltag column='nomdia' tagname='DESCRIPTION' /> </xmltags> </sql.toXML> </xml.diary> </set> <return name='cdiary.xml' type='text/xml'> <string.getBytes><m_xml /></string.getBytes> </return> </body> </xsql-script>