XML Documents

XML documents are strictly text files. In the context of data transport, the phrase "XML document" refers to a file or data stream containing any form of structured data. Examples include e-commerce transactions, server APIs, mathematical equations, customer information, and inventory status.

XML documents contain only markup and content. All of the rules and semantics of the document are defined by the applications that process them. Like HTML documents, XML documents can be displayed in a Web browser. In this case, the semantics are usually derived from style sheets or Resource Description Framework (RDF) files.

XML documents are said to be either "well-formed" or "valid." Well-formed documents follow all of the XML rules for a document–for example, for every start tag, there is a corresponding end tag. Valid XML documents are well-formed, but they also contain a document type definition (DTD), and they obey the constraints of that definition. For example, the following XML file contains a DTD that describes all the elements of the file:

<?xml version = "1.0"?>
<!DOCTYPE ORDERFILE [
<!ELEMENT ORDERFILE (CUSTOMER)*>
<!ELEMENT CUSTOMER (NAME, DATE, ORDERS)>
<!ELEMENT NAME (LAST-NAME, FIRST-NAME)>
<!ELEMENT LAST-NAME (#PCDATA)>
<!ELEMENT FIRST-NAME (#PCDATA)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT ORDERS (ITEM)*>
<!ELEMENT ITEM (PRODUCT, NUMBER, (PRICE | CHARGEACCT | SAMPLE))>
<!ELEMENT PRODUCT (#PCDATA)>
<!ELEMENT NUMBER (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>
<!ELEMENT CHARGEACCT (#PCDATA)>
<!ELEMENT SAMPLE (#PCDATA)>
]>
<ORDERFILE>
    <CUSTOMER>
        <NAME>
            <LAST-NAME>Smith</LAST-NAME>
            <FIRST-NAME>Sam</FIRST-NAME>
        </NAME>
        <DATE>October 15, 2001</DATE>
        <ORDERS>
            <ITEM>
                <PRODUCT>Tomatoes</PRODUCT>
                <NUMBER>8</NUMBER>
                <PRICE>1.25</PRICE>
            </ITEM>
            <ITEM>
        <PRODUCT>Apples</PRODUCT>
                <NUMBER>12</NUMBER>
                <PRICE>2.50</PRICE>
            </ITEM>
            <ITEM>
        <PRODUCT>Bananas</PRODUCT>
                <NUMBER>6</NUMBER>
                <PRICE>.50</PRICE>
            </ITEM>
        </ORDERS>
    </CUSTOMER>
    <CUSTOMER>
        <NAME>
            <LAST-NAME>Snead</LAST-NAME>
            <FIRST-NAME>Todd</FIRST-NAME>
        </NAME>
        <DATE>October 17, 2001</DATE>
        <ORDERS>
            <ITEM>
                <PRODUCT>Slicer/Dicer</PRODUCT>
                <NUMBER>1</NUMBER>
                <CHARGEACCT>1234-5678-3456-7890</CHARGEACCT>
            </ITEM>
        </ORDERS>
    </CUSTOMER>
</ORDERFILE>

Documents that include and obey a schema rather than a DTD are considered to be "schema-valid." Schemas are files describing the XML document and its precise structure. XML documents that are accompanied by schemas produce the most reliable FDs and SELECT statements when run through the xml2fd utility, especially if the schema has information about data types and lengths.

Note:

Please note that the xml2fd utility is used exclusively with AcuXML. If you are calling the C$XML library routine, you do not need to run XML documents through xml2fd.

Following is an example of a schema file for the same XML document. As you can see, it is much more descriptive than the DTD.

 
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:documentation>
      Created by AcuXML(tm) version 6.0.0 (2002-11-12) on 2002/11/12
    </xs:documentation>
  </xs:annotation>

  <xs:element name="TEST-ORDERFILE">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="CUSTOMER"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="CUSTOMER">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="NAME"/>
        <xs:element ref="DATE"/>
        <xs:element ref="ORDERS"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="NAME">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="LAST-NAME"/>
        <xs:element ref="FIRST-NAME"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="ORDERS">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="ITEM" maxOccurs="3"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="ITEM">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="PRODUCT"/>
        <xs:element ref="NUMBER"/>
        <xs:element ref="PRICE"/>
        <xs:element ref="CHARGEACCT"/>
        <xs:element ref="SAMPLE"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="LAST-NAME">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="5"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="FIRST-NAME">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="4"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="DATE">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="16"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="PRODUCT">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="12"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="NUMBER">
    <xs:simpleType>
      <xs:restriction base="xs:integer">
        <xs:totalDigits value="2"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="PRICE">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="4"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="CHARGEACCT">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="19"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

  <xs:element name="SAMPLE">
    <xs:simpleType>
      <xs:restriction base="xs:integer">
        <xs:totalDigits value="1"/>
      </xs:restriction>
    </xs:simpleType>
  </xs:element>

</xs:schema>

ACUCOBOL-GT applications can read and write any type of XML data. Typically, the party with whom you are exchanging data will require that the data include a DTD. Occasionally, they may require a schema for their own development work.

With AcuXML, you can specify the type of XML output that you want to generate. You use the configuration variable AXML_CREATE_STYLE. If you want the output to include a schema, you set AXML_CREATE_STYLE to "schema", and then use another configuration variable to define the schema name (AXML_SCHEMA_NAME). By default, a schema is then created each time ACUCOBOL-GT generates XML output. To prevent this for subsequent output, you can set a third configuration variable, AXML_CREATE_SCHEMA, to "false", then just the name of the schema file is included. Configuration variables are described in Configuration Variables.