Home » Developer & Programmer » JDeveloper, Java & XML » Adding extra tags using dbms_xmlquery
Adding extra tags using dbms_xmlquery [message #227826] Thu, 29 March 2007 09:38
pkirangi
Messages: 74
Registered: August 2005
Member
Hi The following block of code :
DECLARE
  queryCtx dbms_xmlquery.ctxType;
  result CLOB;
BEGIN
  -- set up the query context
  queryCtx := dbms_xmlquery.newContext(
    'SELECT empno "EMP_NO"
          , ename "NAME"
          , deptno "DEPT_NO"
       FROM emp
      WHERE deptno = :DEPTNO'
  );

dbms_xmlquery.setRowTag(
      queryCtx
    , 'EMP'
  );
  dbms_xmlquery.setRowSetTag(
      queryCtx
    , 'EMPSET'
  );
dbms_xmlquery.setBindValue(
      queryCtx
     , 'DEPTNO'
     , 10
  );
 result := dbms_xmlquery.getXml(queryCtx);
  printClobOut(result);
  dbms_xmlquery.closeContext(queryCtx);
END;


has the following output:

<?xml version = '1.0'?>
<EMPSET>
   <EMP num="1">
      <EMP_NO>7782</EMP_NO>
      <NAME>CLARK</NAME>
      <DEPT_NO>10</DEPT_NO>
   </EMP>
   <EMP num="2">
      <EMP_NO>7839</EMP_NO>
      <NAME>KING</NAME>
      <DEPT_NO>10</DEPT_NO>
   </EMP>
   <EMP num="3">
      <EMP_NO>7934</EMP_NO>
      <NAME>MILLER</NAME>
      <DEPT_NO>10</DEPT_NO>
   </EMP>
</EMPSET>


I need to have an additional tag on t he outside like this:
<?xml version = '1.0'?>
<RESULTSET>
<EMPSET>
   <EMP num="1">
      <EMP_NO>7782</EMP_NO>
      <NAME>CLARK</NAME>
      <DEPT_NO>10</DEPT_NO>
   </EMP>
   <EMP num="2">
      <EMP_NO>7839</EMP_NO>
      <NAME>KING</NAME>
      <DEPT_NO>10</DEPT_NO>
   </EMP>
   <EMP num="3">
      <EMP_NO>7934</EMP_NO>
      <NAME>MILLER</NAME>
      <DEPT_NO>10</DEPT_NO>
   </EMP>
</EMPSET>
<RESULTSET>


How do I acheive this?



Previous Topic: recordset in JDeveloper
Next Topic: how to insert attributes in xml while generating from package dbms_xmlgen
Goto Forum:
  


Current Time: Fri Mar 29 04:10:14 CDT 2024