Please enable JavaScript to view this site.

Altova XMLSpy 2020 Professional Edition

XMLSpy provides two evaluations of the XML document:


A well-formedness check

A validation check


If either of these checks fails, we will have to modify the document appropriately.


Since the Validation on Modification feature is switched on by default, any validation error created during editing will be immediately flagged, with the error message/s being displayed in the Messages Window. If you do not want background validation, you can switch off Validation on Modification in the Validation settings of the Options dialog. In the event you do this, note that you can always carry out well-formed checks and validation checks separately at any time. How to do this is described below.


Checking well-formedness

An XML document is well-formed if starting tags match closing tags, elements are nested correctly, there are no misplaced or missing characters (such as an entity without its semi-colon delimiter), etc.


You can do a well-formedness check in any editing view. Let us select Text View. To do a well-formedness check, select the menu option XML | Check well-formedness, or press the F7 key, or click ic_well_formed. A message appears in the Messages window at the bottom of the Main Window saying the document is well-formed.


Notice that the output of the Messages window has 9 tabs. The validation output is always displayed in the active tab. Therefore, you can check well-formedness in Tab1 for one schema file and keep the result by switching to Tab2 before validating the next schema document (otherwise Tab1 is overwritten with the validation result ).


Note:This check does not check the structure of the XML file for conformance with the schema. Schema conformance is evaluated in the validity check.


Checking validity

An XML document is valid according to a schema if it conforms to the structure and content specified in that schema.


To check the validity of your XML document, first select Grid View, then select the menu option XML | Validate, or press the F8 key, or click ic_validate. An error message appears in the Messages window saying the file is not valid. Mandatory elements are expected after the City element in Address. If you check your schema, you will see that the US-Address complex type (which you have set this Address element to be with its xsi:type attribute) has a content model in which the City element must be followed by a Zip element and a State element.


Fixing the invalid document

The point at which the document becomes invalid is highlighted, in this case the City element.


Now look at the Elements Entry Helper (at top right). Notice that the Zip element is prefixed with an exclamation mark, which indicates that the element is mandatory in the current context.


To fix the validation error:


1.In the Elements Entry Helper, double-click the Zip element. This inserts the Zip element after the City element (we were in the Append tab of the Elements Entry Helper).

2.Press the Tab key, and enter the Zip Code of the State (04812), then confirm with Enter. The Elements Entry Helper now shows that the State element is mandatory (it is prefixed with an exclamation mark). See screenshot below.


3.In the Elements Entry Helper, double-click the State element. Then press Tab and enter the name of the state (Texas). Confirm with Enter. The Elements Entry Helper now contains only grayed-out elements. This shows that there are no more required child elements of Address.



Completing the document and revalidating

Let us now complete the document (enter data for the Person element) before revalidating.


Do the following:


1.Click the value field of the element First, and enter a first name (say Fred). Then press Enter.


2.In the same way enter data for all the child elements of Person, that is, for Last, PhoneExt, and Email. Note that the value of PhoneExt must be an integer with a maximum value of 99 (since this is the range of allowed PhoneExt values you defined in your schema). Your XML document should then look something like this in Grid View:


3.Click ic_validate again to check if the document is valid. A message appears in the Messages window stating that the file is valid. The XML document is now valid against its schema.


4.Select the menu option File | Save and give your XML document a suitable name (for example CompanyFirst.xml). Note that the finished tutorial file CompanyFirst.xml is in the Tutorial folder, so you may need to rename it before you give that name to the file you have created.


Note:An XML document does not have to be valid in order to save it. Saving an invalid document causes a prompt to appear warning you that you are about to save an invalid document. You can select Save anyway, if you wish to save the document in its current invalid state.


© 2020 Altova GmbH