HTML and CSS Reference
validated against the schema. If there are any validation errors, the ValidationEventHandler event is
raised. The event-handler function OnValidationError stores the XML file name and the error message in a
Once all the uploaded XML files are validated, the code iterates through the generic list of errors and
creates a bulleted list of the error messages. The error list is returned to the jQuery success function by
converting it to JSON format.
To test the application, run it and try uploading XML files—some matching the schema and some
violating the schema (for example, keep some <employee> elements without an employeeid attribute). You
should get error messages for any invalid XML files.
HTML5's File API allows you to read files residing in the user's local file system. The files, however, must be
explicitly selected by the user using a file field control's Open File dialog or by dragging them from
Windows Explorer and dropping them onto a predefined area of a web page.
The File API consists of three main objects: File , FileList , and FileReader . The File object gives
information about a file such as its name, size, and MIME type. The FileList object is a collection of File
objects and is obtained either via the iles property of a file field or via the iles property of a dataTransfer
object. The FileReader object lets you read selected files in asynchronous fashion.
Although drag-and-drop is an independent feature of HTML5, it can be coupled with the File API to
enhance the user experience. Selected files can be uploaded to the server using the $.ajax() method.
The next chapter introduces another interesting feature—web workers—that allows you to run code
in the background. Web workers are like threads used in a multithreaded desktop application in that they
let you run lengthy processes in the background without obstructing the user interface.