The concept of well-formed
Before you can use an XML document in any capacity, it must be well-formed. The problem is that most developers don’t speak XML, and you won’t use production data to gain experience working with XML in most cases. The files you create for experimentation purposes must be well-formed too.
Fortunately, you don’t have to invest in fancy software to check your work or rely on someone else’s eyes to find the mistakes you’ve made. A number of sites provide XML validators you can use for checking your work. Two such sites are:
In both cases, you simply copy and paste your XML into the window provided and click a button, and the application tells you about any errors in your file. Both sites also provide a means for working with complete files, rather than using the cutting and pasting approach.
The fact that an XML document is well-formed doesn’t say much. It’s easy to create a well-formed XML document that won’t work because the structure is incorrect. For example, the data might not include a required node, or the node might use the wrong capitalization or be misspelled.
All sorts of errors can creep into data files that aren’t validated in some way. The use of XML Schema Definition (XSD) files makes it possible to check the precise structure of a file and display a list of errors in it.
Using XSD is an important technique in situations where data errors of any sort could be catastrophic. (Think about banking or medical records.) You can gain a better understanding of XSD through the excellent W3Schools tutorial. The CodeGuru tutorial is shorter but provides helpful information on this technique as well.