Validating Your XML and Fixing Errors
Validating your XML
To be "valid," your XML file must meet two criteria:
- It must be "well formed," meaning that it must have correct syntax. In general terms, this means that all opening elements have matching closing elements.
- It must conform to the DTD (Document Type Definition) that defines the structure of a TEI-XML file.
To validate your file, click on the red checkmark icon or pressing ctrl + shift + v (PC) or cmd + shift + v (Mac). If the red checkmark icon isn't visible, you can select Window > Configure Toolbars, and make sure that the Validate toolbar is checked.
If there are no problems, you'll see a "Validation successful" message at the bottom of the screen. If not, you'll see "Validation failed" and a list of errors.
There are three main things to keep in mind:
- One error can cause any number of other errors. In many cases, if you fix the first error, many or all of the others may go away.
- The following validation error is extremely common: "The element type 'p' must be terminated by the matching end tag '</p>.'" This generally means there is an opening element of some sort without a matching ending element, or vice versa (not necessarily a <p> element, as the error message suggests).
- When you click on an error in the list, the editor will take you to the place in the file where it has identified the problem. This is often not quite the right spot. It's safe to assume, however, that the problem is prior to that spot, and in most cases, not too far ahead of it. Work back from there, making sure that all opening elements have matching closing elements.
Avoiding Messy Validation Problems
The editor will flag many problems before you ever try to validate the file, by underlining offending material with a red squiggly line. Fix these problems as you go.
The other way to avoid running into difficult-to-solve problems is to validate often. If you were to validate, say, after ever few lines of text that you enter, you'll know more or less where the problem has to be if the validator flags one.