Altova XMLSpy 2024 Enterprise Edition

ic_validate        F8

The XML | Validate (F8) command enables you to validate XML documents against DTDs, XML Schemas, and other schemas. Validation is automatically carried out when you switch from Text View to any other view. You can specify that a document be automatically validated when a file is opened or saved (Tools | Options | File). The Validate command also carries out a well-formedness check before checking validity, so there is no need to use the Check Well-Formedness command before using the Validate command.

 

Note:        You can also toggle on the Validate on Edit command to validate as you edit data.-

 

If a document is valid, a successful validation message is displayed in the Messages window.

valid

Otherwise, a message that describes the error is displayed. You can click on the links in the error message to jump to the node in the XML document where the error was found. See the next section below for a description of the error message and how to fix validation errors with the smart fixes of XMLSpy.

 

Validation errors and their fixes

When a validation error is displayed in the Messages window, the causes of the error are displayed in the left-hand pane (see screenshot below). If a cause is selected in the left-hand pane, then smart fixes for it, if available, are displayed in the right-hand pane. Smart fix suggestions are available in Text View and Grid View, and are based on information in the associated schema. To view smart fixes, click the Show Smart Fix button. Click Hide Smart Fix if you do not want these suggestions to be displayed. Note that errors of well-formedness (such as mismatched start and end tags), if such exist, are displayed prior to validation errors being displayed. So the Show/HIde Smart Fix button will be enabled only when a validation error is reached (that is, after alll well-formedness errors have been corrected).

Click to expand/collapse

To apply a smart fix, either (i) double-click it, or (ii) select it and click either the Fix or Fix + Validate options (see screenshot below). The Fix + Validate command will validate beyond the fixed error and pick up the next error, if there is any.

ValidateXMLAutoFix

In Text View, there are two additional indicators of a validation error (see screenshot below): (i) a red exclamation-mark icon in the line-numbering margin, and (ii) a red marker-square in the scroll bar (on the right of the window).

TextViewValErrorIndicators

The light-bulb icon next to the exclamation-mark icon (see screenshot above) is the smart-fix icon. If you hover over it, all smart fixes across all causes of the error are displayed (see screenshot below). Select a smart fix to apply it.

TextViewValErrorSmartFixes
Note:The validation error indicators and smart fixes described above are refreshed only when the XML | Validate (F8) command is executed; they are not updated in the background. So, after correcting an error, you must run the Validate (F8) command again to make sure that the error has indeed been fixed.

 

Note:The Messages window has nine tabs. The validation result is always displayed in the active tab. So you can validate one XML document in Tab-1 and retain the result in that tab. To validate a second document, switch to Tab-2 (or Tab-3 if you like) before running the check. If you do not switch tabs, Tab-1 (or the active tab) will be overwritten with the results of the latest validation.

 

Validating from the Project window

The Validate command can also be applied to a file, folder, or group of files in the active project. Select the required file or folder in the Project Window (by clicking on it). Then click XML | Validate or F8. Invalid files in a project will be opened and made active in the Main Window, and the File is not valid error message will be displayed..

 

Validating XML documents

To validate an XML file, make the XML document active in the Main Window, and click XML | Validate or F8. The XML document is validated against the schema referenced in the XML file. If no reference exists, an error message is displayed in the Messages window. As long as the XML document is open, the schema is kept in memory (see Flush Memory Cache in the DTD/Schema menu).

 

Validating schema documents (DTDs and XML Schema)

XMLSpy supports major schema dialects, including DTD and XML Schema. To validate a schema document, make the document active in the Main Window, and click XML | Validate or F8.

 

Validation messages

There are two kinds of messages:

 

If the schema (DTD or XML Schema) is valid, a successful validation message is displayed in the Messages window.

If the schema is not valid, an error message is displayed in the Messages window (screenshot below).

Click to expand/collapse

An error message shows each possible cause of that error separately. For example, in the screenshot above, four possible causes of the validation error are reported; the first one is expanded, the other three are collapsed. Each cause is divided into three parts:

 

1.  A description of the possible cause. The description contains links to the relevant definition in the associated schema document. You can quickly go to the specific schema definition to see why exactly the document is invalid.

2.  The location path to the node in the XML document that has caused the error. Clicking any node in this location path highlights that node in the document.

3.  Detailed information about the error, as well as a link to the relevant paragraph in the schema specification. This is where the schema rules that specify the relevant legality are specified.

 

Note:If the validation is done in Text View, then clicking a link in the Messages window will highlight the corresponding definition in Text View. If the validation is done in Schema View, then clicking a definition link will open the definition in Schema View and allow you to edit the component directly.

 

Catalogs

For information about catalog support in XMLSpy, see the section Catalogs in XMLSpy.

 

Automating validation with RaptorXML 2024

RaptorXML is Altova's standalone application for XML validation, XSLT transformation, and XQuery transformation. It can be used from the command line, via a COM interface, in Java programs, and in .NET applications. Validation tasks can therefore be automated with the use of RaptorXML. For example, you can create a batch file that calls RaptorXML to perform validation on a set of documents and sends the output to a text file. See the RaptorXML documentation for details.

 

© 2017-2023 Altova GmbH