xml spy
Previous  Top  Next
Validating and entering data

At this point let's check if the document is well-formed and valid, there might still be work to do.

To check for well-formedness: ic_well_formed
1.Select the menu option XML | Check well-formedness or hit the F7 key.  
A message appears at the bottom of the main window declaring that the document is well formed. Click OK to confirm and close the message.  

tut_43a  

Being well-formed, means that the XML document syntax is correct (i.e. there is a root element, each start tag has a corresponding end tag, all elements are nested correctly etc.).  

This check does not check against a schema file (or any other external file). Element sequence or element content are not checked either.  

To check for validity: ic_validate
1. Select the menu option XML | Validate or hit the F8 key.  
An error message appears: "This file is not valid: Mandatory elements expected after 'City' (Zip, State).  
The error message describes in detail what is currently wrong with our XML document.  

tut_43b  

Fixing the invalid document (intelligent help):
At this point the element which is the "cause" of the error message is highlighted (City).
Take note of the Element entry helper (top right). The Zip element is prefixed by an exclamation mark. This is the symbol for a mandatory element, and means that the US-Address element must contain the Zip sub-element.

tut_44a  

1.Double click the !Zip element in the Element entry helper.  
This inserts the Zip element under the City element (Append tab is active by default).  
2.Hit the Tab key, enter the Zip Code of the State (04812), and confirm with Enter.  
The Element entry helper now contains the !State entry, which is also a mandatory element and must also appear with the Zip element.  

tut_44b  

3.Double click the !State element, hit the Tab key and enter the name of the state (e.g. Texas), confirm with Enter.  
The Element entry helper now contains only grayed-out elements. This shows that all the required Address sub-elements have been inserted.  

tut_45a  

Filling in the rest of the XML document data & revalidating
1.Click the empty element content field (right of element name) of the element First, enter the persons first name (e.g. Fred), and hit the Enter key.  

tut_45b  

2.Hit the Down arrow key, and fill in the next field, Last (e.g. Smith)  
3.Use the same method to enter PhoneExt (e.g. 22) and the persons e-mail address (e.g. smith@work.com). You XML document should look like this:  

tut_46a  

4.Click the Revalidate button to check if the document is valid.  
The "This file is valid" message appears. The XML document is now valid against its schema. Click OK to confirm and close the message.  

tut_46b  

Being valid, means that the XML document adheres to the assigned schema i.e. the elements and the sequence they appear in is correct, as well as the element "contents" and their attributes.  

5.Select the menu option File | Save As... and name the XML document (e.g. CompanyFirst.xml)  

This XML document is available as 'CompanyFirst.xml' in the Tutorial folder.  

Please note:  
An XML document does not have to be valid in order to save it. Saving an invalid document causes a prompt to appear which then allows you to select "Save anyway", the document is then saved in its current state.  

Previous  Top  Next

© 2002 Altova