Below it is shown an example of script which uses SOAP and DOM. The objective is the copy of objects of a dictionary base to another.

1 Examples of transaction digestion

Copy
<xsql-script name='test'>
   <body>
        <system.setManager />
        <println />
        <println>OBJECT COPY OF A ORIGIN DICTIONARY TO A DESTINATION ONE</println>
        <println>======================================================</println>
        <println />

        <!-- Data of the origin -->
        <set name='m_src_dbs'><system.prompt>origin dictionary BD........: </system.prompt></set>
        <set name='m_src_obj'><system.prompt>Object code.................: </system.prompt></set>

        <!-- Check that the Object exists in the origin database. -->
        <connection name='#m_src_dbs'>
            <if>
                <expr>
                    <not>
                        <select>
                            <columns>rep_code</columns>
                            <from table='wic_jrep_object' />
                            <where>rep_code = <m_src_obj/></where>
                        </select>
                    </not>
                </expr>
                <then>
                    <println />
                    <println>:ERROR: The SQL Object [<m_src_obj />] does not exist in the database <m_src_dbs /></println>
                    <println />
                    <return />
                </then>
            </if>
        </connection>

        <set name='m_cond'>
            <string>rep_code='<m_src_obj />'</string>
        </set>

        <println />
        <println>Connected to <m_src_dbs/> to obtain [<m_src_obj/>] ...</println>
        <println />

        <connection name='#m_src_dbs'>
            <set name='m_xml'>
                <soap.buildTransaction tabname='wic_jrep_object' condition='#m_cond' recursive='true' />
            </set>
        </connection>

        <!-- Check that there is a XML document (there is register) -->
        <if>
            <expr><eq><string.length><m_xml /></string.length>0</eq></expr>
            <then>
                <println>:ERROR: The SQL object [<m_src_obj />] does not exist in the database <m_src_dbs /></println>
                <println />
                <return />
            </then>
        </if>

        <!-- Data of the destination -->
        <set name='m_dst_dbs'><system.prompt>destination origin BD ...........: </system.prompt></set>
        <set name='m_dst_rol'><system.prompt>Functional group of the object...: </system.prompt></set>
        <set name='m_dst_obj'><system.prompt>Code of the new object...........: </system.prompt></set>

        <!-- Check that the new Object dies not exist already in the destination bd. -->
        <connection name='#m_dst_dbs'>
            <if>
                <expr>
                    <select>
                        <columns>rep_code</columns>
                        <from table='wic_jrep_object' />
                        <where>rep_code = <m_dst_obj/></where>
                    </select>
                </expr>
                <then>
                    <println />
                    <println>:ERROR: The SQL Object [<m_dst_obj />] already exist in the database <m_dst_dbs /></println>
                    <println />
                    <return />
                </then>
            </if>
        </connection>

        <!-- Parser of the XML -->
        <set name='m_root'><dom.parse><m_xml /></dom.parse></set>

        <!-- Substitution of the functional role of origin by the functional role destination. -->
        <set name='m_node_role'>
            <dom.node.getFirstChild>
                <dom.getElementByXPath xpath="/sqltransaction/atomic/insert/row/rep_role">
                    <m_root/>
                </dom.getElementByXPath>
            </dom.node.getFirstChild>
        </set>
        <dom.setNodeValue value='#m_dst_rol'><m_node_role /></dom.setNodeValue>

        <!-- Substitution of the origin object code for the destination object code. -->
        <set name='m_node_code'>
            <dom.node.getFirstChild>
                <dom.getElementByXPath xpath="/sqltransaction/atomic/insert/row/rep_code">
                    <m_root/>
                </dom.getElementByXPath>
            </dom.node.getFirstChild>
        </set>
        <dom.setNodeValue value='#m_dst_obj'><m_node_code /></dom.setNodeValue>

        <println />
        <println>Connected to <m_dst_dbs/> para transferir [<m_src_obj/>] ...</println>
        <println />

        <connection name='#m_dst_dbs'>
            <set name='m_result'>
                <soap.digestTransaction>
                    <m_root />
                </soap.digestTransaction>
            </set>
        </connection>

        <!-- Result -->
        <set name='m_node_sqlinfo'>
            <dom.node.getFirstChildElement><m_result/></dom.node.getFirstChildElement>
        </set>

        <println>COMMITS: <dom.node.getAttribute attr='commits'><m_node_sqlinfo /></dom.node.getAttribute></println>
        <println>DELETES: <dom.node.getAttribute attr='deletes'><m_node_sqlinfo /></dom.node.getAttribute></println>
        <println>INSERTS: <dom.node.getAttribute attr='inserts'><m_node_sqlinfo /></dom.node.getAttribute></println>
        <println>UPDATES: <dom.node.getAttribute attr='updates'><m_node_sqlinfo /></dom.node.getAttribute></println>
        <println>ROLLBACKS: <dom.node.getAttribute attr='rollbacks'><m_node_sqlinfo /></dom.node.getAttribute></println>
        <println />

        <if>
            <expr>
                <ne><dom.node.getAttribute attr='rollbacks'><m_node_sqlinfo /></dom.node.getAttribute>0</ne>
            </expr>
            <then>
                <println>    :ERROR !!!!</println>
                <println/>

                <println><m_result /></println>
            </then>
        </if>
   </body>
</xsql-script>