Editing XML documents

 Associate a schema to a document

 Setting a schema for the Content Completion

In case you are editing document fragments, for instance the chapters from a book each one in a separate file, you can activate the Content Completion for these fragments in two ways:

 Setting a default schema

The table available at OptionsPreferences -> Content Completion/Default contains a set of rules for associating a schema with the current document when no schema is specified within the document. The schema is one of the types: XML Schema, XML Schema with embedded Schematron rules, Relax NG, Relax NG with embedded Schematron rules, Schematron, DTD, NRL.

The rules are applied in the order they appear in the table and take into account the local name of the root element, the default namespace and the file name of the document.

[Important]Important

The editor is creating the Content Completion lists by analysing the specified schema and the current context (the position in the editor). If you change the schema you can observe that the list of tags to be inserted is changing.

 

Figure 4.18. Content completion driven by a Docbook DTD

Content completion driven by a Docbook DTD


 Adding a Processing Instruction

The same effect is obtained by configuring a processing instruction that specifies the schema to be used. The advantage of this method is that you can configure the Content Completion for each file. The processing instruction must be added at the beginning of the document, just after the XML prologue:

<?oxygen RNGSchema="file:/C:/work/relaxng/personal.rng" type="xml"?>

Select menu Document+XML DocumentAssociate schema... or click the toolbar button Associate schema to open a dialog for selecting a schema used for Content Completion and document validation. The schema is one of the types: XML Schema, DTD, Relax NG, NRL, Schematron.

This is a dialog helping the user to easily associate a schema file with the edited document . Enables definition of a XML Document Prolog using the system identifier of a XML Schema, DTD, Relax NG (full or compact syntax) schema, NRL (Namespace Routing Language) schema or Schematron schema.

 

Figure 4.19. Associate schema dialog

Associate schema dialog

When associating a XML Schema to the edited document if the root element of the document defines a default namespace URI with a "xmlns" attribute the "Associate schema" action adds a xsi:schemaLocation attribute. Otherwise it adds a xsi:noNamespaceSchemaLocation attribute.

The URL combo box contains a predefined set of schemas that are used more often and it also keeps a history of the last used schemas.

<oXygen/> logs the URL of the detected schema in the Information view.

The oxygen processing instruction has the following attributes:

RNGSchema
specifies the path to the Relax NG schema associated with the current document
type
specifies the type of Relax NG schema, is used together with the RNGSchema attribute and can have the value "xml" or "compact".
NRLSchema
specifies the path to the NRL schema associated with the current document
SCHSchema
specifies the path to the SCH schema associated with the current document

 Learning document structure

When working with documents that do not specify a schema, or for which the schema is not known or does not exist, <oXygen/> is able to learn and translate it to a DTD, which in turn can be saved to a file in order to provide a DTD for Content Completion and document validation. In addition to being useful for quick creation of a DTD that will be capable of providing an initialization source for the Content Completion assistant. This feature can also be used to produce DTDs for documents containing personal or custom element types.

When it is opened a document that does not specify a schema <oXygen/> automatically learns the document structure and uses it for Content Completion. To disable this feature uncheck the checkbox Learn on open document from Preferences.

 

Procedure 4.8. To create a DTD:

  1. Open the structured document from which a DTD will be created.

  2. Select menu Document+XML DocumentLearn Structure (Ctrl+Shift+L) or click the toolbar button Learn structure to read the mark-up structure of the current document so that it can be saved as a DTD using the Save Structure option. <oXygen/> will learn the document structure, when finished displaying words Learn Complete in the Message Pane of the Editor Status bar.

  3. Select menu Document+XML DocumentSave Structure (Ctrl+Shift+S) or click the toolbar button Save structure to display the Save Structure dialog, used to name and create DTD documents learnt by the Learn Structure function.

[Note]Note

The resulting DTD is only valid for documents containing the elements and structures defined by the document used as the input for creating the DTD. If new element types or structures are defined in a document, they must be added to the DTD in order for successful validation.