Posted on Thursday, 17th December 2009 by Balazs

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


Share and Enjoy:
  • Print
  • LinkedIn
  • Facebook
  • FriendFeed
  • Twitter
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks
  • Slashdot
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • RSS
  • Ping.fm
  • email
  • PDF

Tags: , , , , , ,
Posted in DB2 | Comments (Comments)

blog comments powered by Disqus