Validating XML documents against a schema

A Valid XML document is a Well Formed XML document, which also conforms to the rules of a schema which defines the legal elements of an XML document. The schema type can be: XML Schema, Relax NG (full or compact syntax), Schematron, Document Type Definition (DTD), Namespace Routing Language (NRL) or Namespace-based Validation Dispatching Language (NVDL).

The purpose of the schema is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements.

The <oXygen/> Validate document function ensures that your document is compliant with the rules defined by an associated DTD, XML Schema, Relax NG or Schematron schema. XML Schema or Relax NG Schema can embed Schematron rules. For Schematron it is possible to select the validation phase.

[Note]Note

Validation of an XML document against a W3C XML Schema containing a type definition with a minOccurs or maxOccurs attribute having a value larger than 256 limits the value to 256 and issues a warning about this restriction in the Message panel at the bottom of the <oXygen/> window. Otherwise for large values of the minOccurs and maxOccurs attributes the validator fails with an OutOfMemory error which practically makes <oXygen/> unusable without a restart of the entire application.

[Note]Note

Validation of an XML document against a deeply recursive Relax NG schema may fail with a stack overflow error. It happens very rarely and the cause is the unusual depth of the Relax NG pattern recursion needed to match an element of the document against the schema and the depth exceeds the default stack size allocated by the Java virtual machine. The error can be overcome by simply setting a larger stack size to the JVM at startup using the -Xss parameter, for example -Xss1m.

[Note]Note

Validation of an XML document against a W3C XML Schema or Relax NG Schema with embedded ISO Schematron rules allows XPath 2.0 in the expressions of the ISO Schematron rules. This ensures that both XPath 1.0 and XPath 2.0 expressions are accepted in the embedded ISO Schematron rules and are enforced by the validation operation. For embedded Schematron 1.5 rules the version of XPath is set with a user preference.

 Marking Validation Errors

A line with a validation error or warning will be marked in the editor panel by underlining the error region with a red color. Also a red sign will mark the position in the document of that line on the right side ruler of the editor panel. The same will happen for a validation warning, only the color will be yellow instead of red.

The ruler on the right of the document is designed to display the errors found during the validation process and also to help the user to locate them more easily. The ruler contains the following areas:

  • top area containing a success validation indicator that will turn green in case the validation succeeded or red otherwise.

    A more detailed report of the errors is displayed in the tool tip. In case there are errors, only the first three of them will be presented in the tool tip;

  • middle area where the errors markers are depicted in red (with a darker color tone for the current selected one). The number of markers shown can be limited by modifying the setting OptionsPreferences+Editor / Document checking+Limit error markers to

    Clicking on a marker will highlight the corresponding text area in the editor. The error message is displayed both in the tool tip and in the error area on the bottom of the editor panel.

    The Document checking user preferences are easily accessible from the button displayed at the beginning of the error message on the bottom of the editor panel.

  • bottom area containing two navigation arrows that will go to the next or to the previous error and a button for clearing all the error markers from the ruler. The same actions can be triggered from Document Validate as you type (Ctrl + .)-> Next error and Document Validate as you type (Ctrl + ,)-> Previous error.

The validation status area is the line at the bottom of the editor panel that presents the message of the current validation error. Clicking on opens the document checking page in <oXygen/> user preferences.

Status messages from every validation action are logged into the Information view.