How Do I: Validate XML Against Its Schema?

When you are authoring XML documents that conform to a schema, you can validate those documents using a third-party XML authoring tool like Altova's XMLSpy. You can open your XML document in XMLSpy and validate it against an XSD file containing your schema.

To Validate an XML Document Using XMLSpy

  1. In XMLSpy, open the XML document you want to validate.
  2. Click the DTD/Schema menu, then click Assign Schema.

    When XMLSpy warns you that your XML may be pretty-printed, click OK.

  3. In the XMLSpy dialog, browse to the location of the XSD file containing the schema against which you want to validate the XML document.
  4. When there is a path to your XML file in the Choose a file box, click OK.

    XMLSpy inserts a schemaLocation attribute at the root element of your XML. This attribute points to the location of your XSD file.

  5. To validate your XML, click the XML menu, then click Validate (you can also press F8).

    If your XML file is valid, XMLSpy will display a "This file is valid" message at the bottom of the window containing your XML. If the XML is invalid, XMLSpy will display a message that indicates what problem may be causing the XML to be invalid.

  6. If your XML is invalid, correct it in keeping with the messages you received from XMLSpy, revalidating until the XML is valid.

Related Topics

Getting Started with XMLBeans