forxmlj, forxmldtdj, forxmlschemaj, forxmlallj

NoteThe functions in this section are Java-based, and you must install them in your server before you can use them. For instructions see Appendix E, “The Java-Based XQL Processor.”.

The Java-based forxml functions map the result set of a SQL query to a SQLX-XML schema, result set document, or both. The SQL query is specified as a character string, containing an arbitrary SQL query expression. When xmlextract and xmltest process the output SQLX-XML documents that forxmlj functions generate, they provide an XML view of the SQL data that is represented by the SQLX-XML documents.

forxmlj is a functional form of the mapping provided by the for xml clause of the select statement. The differences are:

Syntax

forxmljfunction ::=
      forxmlj(sql_query_expression, option_string)
      | forxmldtdj(sql_query_expression, option_string)
      | forxmlschemaj(sql_query_expression, option_string)
 forxmlallj_procedure::=
     execute forxmlallj
        sql_query_expression, option_string
        rs_target_out, schema_target_out, dtd_target_out
 sql_query_expression::=basic_string_expression
 option_string::=basic_string_expression

Description

NoteFor a description of the SQLX-XML representation of SQL result sets, see Chapter 5, “XML Mappings.”

Options

The general format of the option_string is specified in “option_strings: general format”. The options for the for xml clause are specified in Chapter 5, “XML Mappings.”

Exceptions

Any SQL exception raised during execution of the sql_query_expression is raised by the forxmlj function.

Examples

The forxmlj function:

set stringsize 16384 
select forxmlj  
      ("select pub_id, pub_name 
         from pubs2.dbo.publishers", "")  
go

<resultset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<row>
   <pub_id>0736</pub_id>
   <pub_name>New AgeBooks</pub_name>
</row>

<row>
   <pub_id>0877</pub_id>
   <pub_name>Binnet & Hardley</pub_name>
</row>

<row>
   <pub_id>1389</pub_id>
   <pub_name>Algodata Infosystems</pub_name>
</row>

</resultset> 

The forxmldtdj function:

set stringsize 16384 
select forxmldtdj    
      ("select pub_id, pub_name 
         from pubs2.dbo.publishers",     
      "tablename=extract null=omit") 
go

<!ELEMENT extract (row*)>
<!ELEMENT row (pub_id, pub_name?)>
<!ELEMENT pub_id (#PCDATA)>
<!ELEMENT pub_name (#PCDATA)>

The forxmlschemaj function:

set stringsize 16384
select forxmlschemaj
     ("select pub_id, pub_name 
        from pubs2.dbo.publishers",
     "tablename=extract null=omit")

<xsd:schema
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:sqlxml=
   "http://www.iso-standards.org/mra/9075/sqlx">

<xsd:simpleType name="CHAR_4"> 
   <xsd:restriction base="xsd:string">
      <xsd:length value="4"/>
   </xsd:restriction>   
</xsd:simpleType>

<xsd:simpleType name="VARCHAR_40">
   <xsd:restriction base="xsd:string">
      <xsd:length value="40"/>
   </xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="RowType.extract">
   <xsd:sequence>
       <xsd:element name="pub_id" type="CHAR_4"
          minOccurs="0" MaxOccurs="1"/>
        <xsd:element name="pub_name" type="VARCHAR_40"
          minOccurs="0" maxOccurs="1"/>
   </xsd:sequence>
</xsd:complexType>   

<xsd:complexType name="TableType.extract">
   <xsd:sequence>
       <xsd:element name="row" type="RowType.extract"
         minOccurs="0" maxOccurs="unbounded"/>
   </xsd:sequence>
</xsd:complexType>   

<xsd:element name="extract"type="TableType.extract"/>
</xsd:schema> 

The forxmlallj procedure:

set stringsize 16384 
declare @rs varchar(16384) 
declare @schema varchar(16384) 
declare @dtd varchar(16384) 
execute forxmlallj  
  "select pub_id, pub_name from pubs2.dbo.publishers",
  "name=extract  null=attribute",  
  @rs out, @schema    out, @dtd out 
go

<extract 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
   <pub_id>0736</pub_id>
   <pub_name>New Age Books</pub_name>
</row>

<row>
   <pub_id>0877</pub_id>
   <pub_name>Binnet & Hardley</pub_name>
</row>

<row>
   <pub_id>1389</pub_id>
   <pub_name>Algodata Infosystems</pub_name>
</row>
</extract>

<xsd:schema
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:sqlxml=
   "http://www.iso-standards.org/mra/9075/sqlx">
<xsd:simpleType name="CHAR_4">
   <xsd:restriction base="xsd:string">
      <xsd:length value="4"/>
   </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="VARCHAR_40">
   <xsd:restriction base="xsd:string">
     <xsd:length value="40"/>
   </xsd:restriction>
</xsd:simpleType> 

<xsd:complexType name="RowType.extract">
   <xsd:sequence>
     <xsd:element name="pub_id" type="CHAR_4"
          nillable="true" />
     <xsd:element name="pub_name" type="VARCHAR_40"
          nillable="true" />
   </xsd:sequence> 
</xsd:complexType> 

<xsd:complexType name="TableType.extract">
   <xsd:sequence>
      <xsd:element name="row" type="RowType.extract"
         minOccurs="0" maxOccurs="unbounded"/>
   </xsd:sequence>
</xsd:complexType>
<xsd:elementname="extract"type="TableType.extract">
</xsd:schema>

<!ELEMENT extract (row*)>
<!ELEMENT row (pub_id, pub_name)>
<!ELEMENT pub_id (#PCDATA)>
<!ELEMENT pub_name (#PCDATA)>