Example XML and DTD Files

  Return to the Java Programming Corner.


Introduction

All of the examples in the Java XML section uses the test files DatabaseInventory.xml / DatabaseInventory.dtd and Tablespaces.xml.

You can download any of these files by clicking on the and icons.

I also provide the contents of these files below.

NOTE: The DatabaseInventory.dtd file is an external DTD, existing in a separate file from the XML file (DatabaseInventory.xml) referencing it. The DTD file is meant to be referenced from the header of the XML file. Not every browser will display the DTD file directly. For example, if you are using Internet Explorer in Windows, you will see this error message:

Cannot have a DTD declaration outside of a DTD. Line 2, Position 11 

        <!ELEMENT DatabaseInventory (DatabaseName+)>
        ----------^
The reason is that IE does not expect to be interpreting a DTD. It expects to be interpreting an XML file. Just click on View Source to see the DTD file directly.

DatabaseInventory.xml

<?xml version="1.0"?>
<!DOCTYPE DatabaseInventory SYSTEM "DatabaseInventory.dtd">

<DatabaseInventory>

  <DatabaseName>
    <GlobalDatabaseName>production.iDevelopment.info</GlobalDatabaseName>
    <OracleSID>production</OracleSID>
    <DatabaseDomain>iDevelopment.info</DatabaseDomain>
    <Administrator EmailAlias="jhunter" Extension="6007">Jeffrey Hunter</Administrator>
    <DatabaseAttributes Type="Production" Version="9i"/>
    <Comments>
      The following database should be considered the most stable for
      up-to-date data. The backup strategy includes running the database
      in Archive Log Mode and performing nightly backups. All new accounts
      need to be approved by the DBA Group before being created.
    </Comments>
  </DatabaseName>

  <DatabaseName>
    <GlobalDatabaseName>development.iDevelopment.info</GlobalDatabaseName>
    <OracleSID>development</OracleSID>
    <DatabaseDomain>iDevelopment.info</DatabaseDomain>
    <Administrator EmailAlias="jhunter" Extension="6007">Jeffrey Hunter</Administrator>
    <Administrator EmailAlias="mhunter" Extension="6008">Melody Hunter</Administrator>
    <DatabaseAttributes Type="Development" Version="9i"/>
    <Comments>
      The following database should contain all hosted applications. Production
      data will be exported on a weekly basis to ensure all development environments
      have stable and current data.
    </Comments>
  </DatabaseName>

  <DatabaseName>
    <GlobalDatabaseName>testing.iDevelopment.info</GlobalDatabaseName>
    <OracleSID>testing</OracleSID>
    <DatabaseDomain>iDevelopment.info</DatabaseDomain>
    <Administrator EmailAlias="jhunter" Extension="6007">Jeffrey Hunter</Administrator>
    <Administrator EmailAlias="mhunter" Extension="6008">Melody Hunter</Administrator>
    <Administrator EmailAlias="ahunter">Alex Hunter</Administrator>
    <DatabaseAttributes Type="Testing" Version="9i"/>
    <Comments>
      The following database will host more than half of the testing
      for our hosting environment.
    </Comments>
  </DatabaseName>

</DatabaseInventory>

DatabaseInventory.dtd

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT DatabaseInventory (DatabaseName+)>
<!ELEMENT DatabaseName (   GlobalDatabaseName
                         , OracleSID
                         , DatabaseDomain
                         , Administrator+
                         , DatabaseAttributes
                         , Comments)
>
<!ELEMENT GlobalDatabaseName (#PCDATA)>
<!ELEMENT OracleSID          (#PCDATA)>
<!ELEMENT DatabaseDomain     (#PCDATA)>
<!ELEMENT Administrator      (#PCDATA)>
<!ELEMENT DatabaseAttributes EMPTY>
<!ELEMENT Comments           (#PCDATA)>

<!ATTLIST Administrator       EmailAlias CDATA #REQUIRED>
<!ATTLIST Administrator       Extension  CDATA #IMPLIED>
<!ATTLIST DatabaseAttributes  Type       (Production|Development|Testing) #REQUIRED>
<!ATTLIST DatabaseAttributes  Version    (7|8|8i|9i) "9i">

<!ENTITY AUTHOR "Jeffrey Hunter">
<!ENTITY WEB    "www.iDevelopment.info">
<!ENTITY EMAIL  "jhunter@iDevelopment.info">

Tablespaces.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE Tablespaces [

  <!--
   | Used to create all required tablespaces in the database to be used by the 
   | application.
   +-->
  <!ELEMENT Tablespaces (Tablespace+)>

    <!--
     | Any tablespace requires at least one Datafile and an optional (only one)
     | Extent Management clause.
     +-->
    <!ELEMENT Tablespace (Datafile+, ExtentMgt?)>
    <!ATTLIST Tablespace  name     CDATA                  #REQUIRED
                          type     (permanent|temporary)  "permanent"
                          logging  (true|false)           "true">

      <!--
       | The Datafile element requires a file name attribute and can define an 
       | optional "Auto Extend" clause.
       +-->
      <!ELEMENT Datafile (Autoextend?)>
      <!ATTLIST Datafile  name       CDATA         #REQUIRED
                          size       CDATA         "500M"
                          reusefile  (true|false)  "true"
                          autoextend (on|off)      "off">

        <!ELEMENT Autoextend EMPTY>
        <!ATTLIST Autoextend  next  CDATA  "500M"
                              max   CDATA  "unlimited">

      <!--
       | An optional Extent Management clause to declare for each tablespace.
       +-->
      <!ELEMENT ExtentMgt (AllocMethod?)>
      <!ATTLIST ExtentMgt method (local|dictionary) "local">

        <!ELEMENT AllocMethod EMPTY>
        <!ATTLIST AllocMethod  method  (AUTOALLOCATE|UNIFORM) "AUTOALLOCATE"
                               size    CDATA                  "1M">

  ]>


<Tablespaces>

  <Tablespace name="APP_DATA" type="permanent" logging="true">
    <Datafile name="/u10/app/oradata/ERPDB/app_data01.dbf" size="250M" reusefile="true" autoextend="off">
    </Datafile>
    <Datafile name="/u10/app/oradata/ERPDB/app_data02.dbf" size="250M" reusefile="true" autoextend="on">
      <Autoextend next="500M" max="unlimited"/>
    </Datafile>
    <ExtentMgt method="local">
      <AllocMethod method="AUTOALLOCATE"/>
    </ExtentMgt>
  </Tablespace>


  <Tablespace name="APP_INDEX" type="permanent" logging="true">
    <Datafile name="/u09/app/oradata/ERPDB/app_index01.dbf" size="250M" reusefile="true" autoextend="off">
    </Datafile>
    <Datafile name="/u09/app/oradata/ERPDB/app_index02.dbf" size="250M" reusefile="true" autoextend="on">
      <Autoextend next="500M" max="unlimited"/>
    </Datafile>
    <ExtentMgt method="local">
      <AllocMethod method="AUTOALLOCATE"/>
    </ExtentMgt>
  </Tablespace>


  <Tablespace name="APP_TEMP" type="temporary" logging="false">
    <Datafile name="/u07/app/oradata/ERPDB/app_temp01.dbf" size="500M" reusefile="true" autoextend="on">
      <Autoextend next="500M" max="unlimited"/>
    </Datafile>
    <ExtentMgt method="local">
      <AllocMethod method="UNIFORM" size="1M"/>
    </ExtentMgt>
  </Tablespace>

</Tablespaces>