OCM files and namespaces

The OCM file is created by hcixmlcompile from a DTD, an XML document containing a DTD, or a schema document.

See Root names and hcixmlcompile usage.

The OCM file has a namespace= section that is a mapping of namespace URL to namespace prefix. A prefix is generated for each namespace that does not have a predefined prefix. The namespaces that display in this section come from the target namespaces declared in the base schema and any schemas that are imported.

Examples:

  • RootA schema is compiled that has a target namespace of http://www.targeturl.com. This schema imports two other schemas with target namespaces of http://www.schema1targeturl.com and http://www.schema2targeturl.com/purchaseOrder. The first two schemas do not specify a prefix for the target namespace but the third one does.

    The namespace section of the OCM would be:

    namespace=nm1 http://www.targeturl.com
    nm2 http://www.schema1targeturl.com
    po  http://www.schema2targeturl.com/purchaseOrder

    The prefixes nm1 and nm2 are generated by hcixmlcompile because they are not defined in the schema.

    The last prefix, po, was defined in the schema, so that prefix is used.

  • The OCM tree section describes the structure of the message. The elements and attributes that are associated with a namespace have the prefix added to the name.
    nm1:foo {1,1} (,)
           nm2:bar {1,1} (|)
                 #text (str)

    The nm1 prefix associates the element foo with the namespace URL http://www.targeturl.com and the nm2 prefix associates bar with the namespace URL http://www.schema1target.com.

    This prefix is also used in the path for this element, although the actual message being parsed may use a different prefix. When a message is encoded, the prefix from the OCM is used.

  • If the root element is associated with a namespace, then the name of the file must reflect the namespace and the root name.

    Currently, a DTD-generated OCM file that contains a prefixed root element has a file name with the prefix and element name with a $ delimiter. For a Schema generated OCM, the prefix is machine generated. It rarely matches the actual message, and is likely to collide with another OCM file. To solve this problem, the namespace URL of the root element is used.

    A URL can contain characters that are not legal in a file name, so some substitutions are made. As with DTD-generated OCM files:

    • Colons (:) are replaced with dollar signs ($)
    • Slashes, forward or backward, are replaced with percent signs (%)

    In this example, the root element is foo and it is associated with the namespace http://www.example.com/test.

    The file name is http$%%www.example.com%test$foo.

    Note: The maximum file name length is 215 characters, because this is the maximum length accepted by Windows. If the file name is longer than 215 characters, then the namespace URL is truncated to fit.

    This example is true only if -r is used, where you specify the root element for which to generate an OCM.