Manually Defining DTDs

Use the DTD Editor to define DTDs. Uniface uses DTDs to read and write XML streams.

To define a DTD manually:

  1. In the Uniface IDE, choose More Editors >DTD.
  2. In the Definition field of the DTD Editor, define the root element as follows:

    <!ELEMENTRootName(OuterEntity{MultiplicityOperator})>

    For details, see Uniface-Compliant Element Declarations

    All XML streams have a root node, which encloses all the other elements in the stream. The definition of the root element is always the first definition in the DTD.

    At this stage, your DTD should look similar to the following:

    <!ELEMENT ROOT (myentity*)>

    The DTD defines the root element ROOT, which has one child element myentity.

  3. Define elements for each of the Uniface entities in the XML stream (the EntityDefs).

    To do this, declare an element containing elements that represent the fields and inner entities of the entity. Define each entity as follows:

    <!ELEMENTEntityName(
      {InnerEntity1{MultiplicityOperator} | FieldName1}
      {,InnerEntity2{MultiplicityOperator} | FieldName2}...
      {,InnerEntityn{MultiplicityOperator} | FieldNamen})>
    • EntityName—is the name of the element mapped to the Uniface entity.
    • InnerEntity—is the name of an element mapped to an inner entity.
    • FieldName—is the name an element mapped to a field of the Uniface entity.

    At this stage, your DTD should look similar to the following:

    <!ELEMENT ROOT (myentity*)>
    <!ELEMENT myentity (field1, field2, field3, innerentity)>
    <!ELEMENT innerentity (fielda, fieldb, fieldc)>

    The DTD defines elements for two entities, myentity and innerentity, and declares elements for their fields.

  4. Define elements for all the fields of the entities in your DTDs. Define each field as follows:

    <!ELEMENTFieldName (#PCDATA)>

    FieldName is the name of an element representing a field. FieldName must be specified in the declaration of an entity element.

    At this stage, your DTD should look similar to the following:

    <!ELEMENT ROOT (myentity*)>
    <!ELEMENT myentity (field1, field2, field3, innerentity)>
    <!ELEMENT innerentity (fielda, fieldb, fieldc)>
    <!ELEMENT field1 (#PCDATA)>
    <!ELEMENT field2 (#PCDATA)>
    <!ELEMENT field3 (#PCDATA)>
    <!ELEMENT fielda (#PCDATA)>
    <!ELEMENT fieldb (#PCDATA)>
    <!ELEMENT fieldc (#PCDATA)>

    The DTD defines elements for the fields of myentity and innerentity. Note that the only difference between field definitions is the element name.

  5. Define attributes for the elements you declared in steps 2 and 3.

    For details, see Uniface-Compliant Attribute Declarations.

    At this stage, your DTD should look similar to the following (all attributes have been declared):

    <!ELEMENT ROOT (myentity*)>
    <!ELEMENT myentity (field1, field2, field3, innerentity)>
    <!ELEMENT innerentity (fielda, fieldb, fieldc)>
    <!ELEMENT field1 (#PCDATA)>
    <!ELEMENT field2 (#PCDATA)>
    <!ELEMENT field3 (#PCDATA)>
    <!ELEMENT fielda (#PCDATA)>
    <!ELEMENT fieldb (#PCDATA)>
    <!ELEMENT fieldc (#PCDATA)>
    <!ATTLIST myentity id CDATA #REQUIRED>
    <!ATTLIST innerentity id CDATA #REQUIRED>
    <!ATTLIST myentity crc CDATA #REQUIRED>
    <!ATTLIST innerentity crc CDATA #REQUIRED>
    <!ATTLIST myentity status CDATA #REQUIRED>
    <!ATTLIST innerentity status CDATA #REQUIRED>
    <!ATTLIST myentity valerr CDATA #IMPLIED>
    <!ATTLIST innerentity valerr CDATA #IMPLIED>
    <!ATTLIST field1 valerr CDATA #IMPLIED>
    <!ATTLIST field2 valerr CDATA #IMPLIED>
    <!ATTLIST field3 valerr CDATA #IMPLIED>
    <!ATTLIST fielda valerr CDATA #IMPLIED>
    <!ATTLIST fieldb valerr CDATA #IMPLIED>
    <!ATTLIST fieldc valerr CDATA #IMPLIED>

    This DTD uses the processing information attributes required by Uniface for disconnected record sets.

  6. Define a default mapping between elements defined in the DTD and Uniface fields and entities.
  7. Choose File >Validate to validate the DTD.
  8. Choose File >Save, or File >Compile DTD.

Related Topics