Associating a Schema Directly in XML Documents

Associate Schema Action

The schema used by the Content Completion Assistant and document validation engine can be associated with the current document by using the Associate Schema action. For most of the schema types, it uses the xml-model processing instruction, with the exceptions of:

  • W3C XML Schema - The xsi:schemaLocation attribute is used.
  • DTD - The DOCTYPE declaration is used.

The association can specify a relative file path or a URL of the schema. The advantage of relative file path is that you can configure the schema at file level instead of document type level.

To associate a schema to the current document, follow these steps:

  1. Select the Associate Schema action from the toolbar (or DocumentSchema menu).

    Step Result: The Associate Schema dialog box is displayed:

    Associate Schema Dialog Box

    This dialog box contains the following options:

    • URL - Allows you to specify or select a URL for the schema. It also keeps a history of the last used schemas. The URL must point to the schema file that can be loaded from the local disk or from a remote server through HTTP(S), FTP(S).
    • Use path relative to file location - Enable this option if the XML instance document and the associated schema contain relative paths. The location of the schema file is inserted in the XML instance document as a relative file path. This practice allows you, for example, to share these documents with other users without running into problems caused by multiple project locations on physical disk.
    • Schema type - Select a possible schema type from this combo box that is populated based on the extension of the schema file that was entered in the URL field. The possible schema types are: XML Schema, DTD, Relax NG, Relax NG Compact, Schematron, or NVDL.
    • Add additional association for embedded schematron rules - If you have selected XML Schema or Relax NG schemas with embedded Schematron rules and you want to use those embedded rules, enable this option.
    • Public ID - Allows you to specify a public ID if you have selected a DTD.
    • Keep existing schema associations - Enable this option to use the existing schema associations of the currently edited document.

  2. Select the schema that will be associated with the XML document and configure the rest of the options according to your preferences.
  3. Click OK.

Result: The schema association is created based upon the specified type.

  • XML Schema - The association with an XML Schema is added as an attribute of the root element with one of the following:
    • xsi:schemaLocation attribute, if the root element of the document sets a default namespace with an xmlns attribute.
    • xsi:noNamespaceSchemaLocation attribute, if the root element does not set a default namespace.
  • DTD - The association with a DTD is added as a DOCTYPE declaration.
  • Other - The association with a Relax NG, Schematron, or NVDL schema is added as xml-model processing instruction.

Tip

To quickly open the schema used for validating the current document, select the Open Associated Schema action from the toolbar (or XML menu).

Associate Schema with the xml-model Processing Instruction

The xml-model processing instruction associates a schema with the XML document that contains the processing instruction. It must be added at the beginning of the document, just after the XML prolog. The following code snippet contains an xml-model processing instruction declaration:

<?xml-model href="../schema.sch" type="application/xml"
 schematypens="http://purl.oclc.org/dsdl/schematron" phase="ALL"
 title="Main schema"?>

It is available in the Content Completion Assistant, before XML document root element, and includes the following attributes:

  • href (required) - The schema file location.
  • type - The content type of the schema. This is an optional attribute with the following possible values for each specified type:
    • DTD - The recommended value is application/xml-dtd.
    • W3C XML Schema - The recommended value is application/xml, or can be left unspecified.
    • RELAX NG XML Syntax - The recommended value is application/xml, or can be left unspecified.
    • RELAX NG Compact Syntax - The recommended value is application/relax-ng-compact-syntax.
    • Schematron - The recommended value is application/xml, or can be left unspecified.
    • NVDL - The recommended value is application/xml, or can be left unspecified.
  • schematypens - The namespace for the schema language of the referenced schema with the following possible values:
    • DTD - Not specified.
    • W3C XML Schema - The recommended value is http://www.w3.org/2001/XMLSchema.
    • RELAX NG XML Syntax - The recommended value is http://relaxng.org/ns/structure/1.0.
    • RELAX NG Compact Syntax - Not specified.
    • Schematron - The recommended value is http://purl.oclc.org/dsdl/schematron.
    • NVDL - The recommended value is http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0.
  • phase - The phase name for the validation function in Schematron schema. This is an optional attribute. To run all phases from the Schematron, use the special #ALL value. If the phase is not specified, the default phase that is configured in the Schematron will be applied.
  • title - The title for the associated schema. This is an optional attribute.

Older versions of Oxygen XML Author plugin used the oxygen processing instruction with the following attributes:

  • RNGSchema - Specifies the path to the Relax NG schema that is associated with the current document.
  • type - Specifies the type of Relax NG schema. It is used along with the RNGSchema attribute and can have the value xml or compact.
  • NVDLSchema - Specifies the path to the NVDL schema that is associated with the current document.
  • SCHSchema - Specifies the path to the SCH schema that is associated with the current document.

Note

Documents that use the oxygen processing instruction are compatible with newer versions of Oxygen XML Author plugin.

Was this helpful?