Skip to main content

XML

Using XML-SQL Utility (XSU)

XML-SQL Utility (XSU) fornisce un sistema semplice di trasfomazione mappando ogni query SQL con ZML e viceversa. XSU fornisce le funzionalità di base per ottenre e salvare dati da e verso il database.

DECLARE
  queryCtx dbms_xmlquery.ctxType;
  result CLOB;
BEGIN
  -- set up the query context
  queryCtx := dbms_xmlquery.newContext(
    'SELECT ''Miao'' tag1
          , ''Ciao''   tag2
          , ''Bau''    tag3
       FROM dual'
  );
  
  dbms_xmlquery.setRowTag(
      queryCtx
    , 'header'
  );
  dbms_xmlquery.setRowSetTag(
      queryCtx
    , 'message'
  );  
  result := dbms_xmlquery.getXml(queryCtx);
  dbms_output.put_line(result);
  dbms_xmlquery.closeContext(queryCtx);   
end;

E questo è il risultato:

<?xml version = '1.0'?>
<message>
   <header num="1">
      <TAG1>Miao</TAG1>
      <TAG2>Ciao</TAG2>
      <TAG3>Bau</TAG3>
   </header>
</message>

Using XML-SQL Utility (XSU)

XML-SQL Utility (XSU) provides a simple way of achieving data transformation by mapping any SQL query to XML and vice versa. XSU provides the basic functionality to get and put data to and from a database.

DECLARE
  queryCtx dbms_xmlquery.ctxType;
  result CLOB;
BEGIN
  -- set up the query context
  queryCtx := dbms_xmlquery.newContext(
    'SELECT ''Miao'' tag1
          , ''Ciao''   tag2
          , ''Bau''    tag3
       FROM dual'
  );
 
  dbms_xmlquery.setRowTag(
      queryCtx
    , 'header'
  );
  dbms_xmlquery.setRowSetTag(
      queryCtx
    , 'message'
  );  
  result := dbms_xmlquery.getXml(queryCtx);
  dbms_output.put_line(result);
  dbms_xmlquery.closeContext(queryCtx);   
end; 

And this is the result:

<?xml version = '1.0'?>
<message>
   <header num="1">
      <TAG1>Miao</TAG1>
      <TAG2>Ciao</TAG2>
      <TAG3>Bau</TAG3>
   </header>
</message>