XML Features of Oracle 8i and 9i (5/7) - exploring XML | WebReference

XML Features of Oracle 8i and 9i (5/7) - exploring XML

XML Features of Oracle 8i and 9i

XML class generator

This is a tool which converts an input DTD into a set of corresponding java source or class files, which can then be used to create valid XML documents for use with the database.

import oracle.xml.parser.*;
import oracle.xml.classgen.*;
// generate the Java files...
ClassGenerator generator = new ClassGenerator();
// set output directory
generator.setOutputDirectory(".");
// generate java src
generator.generate(dtd, doctype_name);

If a DTD was used corresponding to the employee table emp above, the resulting classes could be used to create valid XML documents containing updated or new employees e.g

public class CreateEmployees {
  EMP EMPLIST = new EMP();
  DTD dtd = EMPLIST.getDTDNode(); // get static from base document
  // New employee emp_row1
  EMP_ROW emp_row1 = new EMP_ROW(1); // create row and set ROWNO
  EMPNO empno1 = new EMPNO("7654");
  ENAME ename1 = new ENAME("MARTIN");
  JOB job1 = new JOB("SALESMAN");
  ...
}

XML in this case would be:

<?xml version="1.0"?>
<!DOCTYPE EMP SYSTEM "employee.dtd">
<EMP>
  <EMP_ROW ROWNO = "1">
    <EMPNO>7654</EMPNO>
    <ENAME>MARTIN</ENAME>
    <JOB>SALESMAN</JOB>
    <MGR>7698</MGR>
    <HIREDATE>1981-09-28 00:00:00.0</HIREDATE>
    <SAL>1250</SAL>
    <COMM>1400</COMM>
    <DEPTNO>30</DEPTNO>
  </EMP_ROW>
<EMP>

Last but nor least the transviewer...


Produced by Michael Claßen

URL: https://www.webreference.com/xml/column81/5.html
Created: May 10, 2003
Revised: May 10, 2003