Register DTD for pureXML with DB2 9.7

Problem

Even though XML schema has been around for a decade, still many APIs reference a DTD in the XML documents sent back and fourth. Such is the OpenSRS API. DB2 requires an XML schema or a DTD to be registered before it will process XML documents that refer to an XML Schema or a DTD. The process of registering such XSROBJECTs with DB2 has changed in DB2 since version 8.

Solution

  • register a DTD using the DB2 9.7 command line:
    db2 CONNECT TO SAMLE
    db2 REGISTER XSROBJECT 'dtd-file-name.dtd' FROM /path/to/dtd/file AS sample.dtd-name DTD

    If the command is successful, the output is
    DB20000I The REGISTER XSROBJECT command completed successfully.
  • Register a DTD from a Java program:
    String schemaName = "SAMPLE";
    String dtdName = "dtd-name";
    String dtdFile = "dtd-file-name.dtd";
    Reader fis = new FileReader(dtdFile);
    byte[] contentDtd = FileIO.readerToString(fis).getBytes();
    String registerProcQuery = "CALL SYSPROC.XSR_DTD (?,?,?,?,?)";
    PreparedStatement registerProcStatement = conn.prepareCall(registerProcQuery);
    registerProcStatement.setString(1, schemaName);
    registerProcStatement.setString(2, dtdName);
    registerProcStatement.setString(3, dtdFile);
    registerProcStatement.setString(4, "PUBLIC ID");
    registerProcStatement.setObject(5, contentDtd, java.sql.Types.BLOB);
    registerProcStatement.execute();

    The FileIO class can be found in Java Cookbook, Second Edition

References


This entry was posted in DB2 and tagged , , , , , , . Bookmark the permalink.

NewPush has solutions to fit your business needs.  For more than a decade, our focus has been to take on the technical challenges that are the hardest and most time-consumming.  Our goal is to free up your resources to focus on the core activities of your business and to drive your business performance.  Please visit our main site at newpush.com for more information or call us at +1-303-423-4500.