Please enable JavaScript to view this site.

Altova XMLSpy 2020 Professional 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.


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


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.


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).


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.


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.



XMLSpy supports a subset of the OASIS XML catalogs mechanism. The catalog mechanism enables XMLSpy to retrieve commonly used schemas (as well as stylesheets and other files) from local user folders. This increases the overall processing speed, enables users to work offline (that is, not connected to a network), and improves the portability of documents (because URIs need to be changed in the catalog files only.) The catalog mechanism in XMLSpy works as follows:


XMLSpy loads a file called RootCatalog.xml, which contains a list of catalog files that will be looked up. You can enter as many catalog files to look up, each in a nextCatalog element in RootCatalog.xml.

The catalog files included in RootCatalog.xml are looked up and the URIs are resolved according to the mappings specified in the catalog files. You should take care not to duplicate mappings, as this could lead to errors.

Two catalog files are supplied with XMLSpy. How these work is described in the section Catalogs in XMLSpy.

The PUBLIC or SYSTEM identifier in the DOCTYPE statement of your XML file will be used for the catalog lookup. For popular schemas, the PUBLIC identifier is usually pre-defined, thus requiring only the URI in the catalog file to be changed when XML documents are used on multiple machines.


When writing your CustomCatalog.xml file (or other custom catalog file), use only the following subset of the OASIS catalog in order for XMLSpy to process the catalog correctly. Each of the elements in the supported subset can take the xml:base attribute, which is used to specify the base URI of that element.




<public publicId="PublicID of Resource" uri="URL of local file"/>

<system systemId="SystemID of Resource" uri="URL of local file"/>

<rewriteURI uriStartString="StartString of URI to rewrite" rewritePrefix="String to replace StartString"/>

<rewriteSystem systemIdStartString="StartString of SystemID" rewritePrefix="Replacement string to locate resource locally"/>

<uri name="filename" uri="URL of file identified by filename"/>






The catalog.xml file in the %AltovaCommonFolder%\Schemas\schema folder contains references to DTDs that implement older XML Schema specifications. You should not validate your XML Schema documents against any of these schemas. The referenced DTD files are included solely to provide XMLSpy with entry helper info for editing purposes should you wish to create documents according to these older recommendations. Also see next point.

If you create a custom file extension for a particular schema (for example, the .myhtml extension for (HTML) files that are to be valid according to the HTML DTD), then you can enable intelligent editing for files with these extensions by adding a line of text to CustomCatalog.xml. For the example extension mentioned, you should add the element <spy:fileExtHelper ext="myhtml" uri="schemas/xhtml/xhtml1-transitional.dtd"/> as a child of the <catalog> element. This would enable intelligent editing (auto-completion, entry helpers, etc) of .myhtml files in XMLSpy according to the XHTML 1.0 Transitional DTD.

For more information on catalogs, see the XML Catalogs specification.


Automating validation with RaptorXML  2020

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.


© 2020 Altova GmbH