XSD Tutorials - Herong's Tutorial Examples - Version 5.10, by Dr. Herong Yang

Validating Non-Conforming XML Documents

This section describes a tutorial example on how to see validation errors on a non-conforming XML document with the assigned XML Schema file (XSD) using XMLPad.

In order to see how XMLPad behaves with XSD validation errors, let's add a new element to our first XML document, first_html_xsd.xml, to make it not conforming with our first XSD document, first_html.xsd.

1. Run XMLPad and click menu File > Open. Select c:\herong\first_html_xsd.xml in the "Open" dialog box. XMLPad displays the XML document in the edit window:

<?xml version="1.0" encoding="utf-8"?>
<html xsi:noNamespaceSchemaLocation="file:///C:/herong/first_html.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<body>My first HTML document in XML format.</body>
</html>

2. Add the "p" element inside the "body" element:

<?xml version="1.0" encoding="utf-8"?>
<html xsi:noNamespaceSchemaLocation="file:///C:/xsd/first_html.xsd"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<body>
<p>My first HTML document in XML format.</p>
</body>
</html>

3. Click menu XML > Validate. XMLPad will validate the current XML document against the rules defined in the assigned XSD file. One validation error will be displayed in the Task List window: "Encountered child p{} that was not expected in element body{} - Line 5".

4. Double click on the error message, XMLPad will display Line 5 in red to highlight where is the error is.
XMLPad - Invalid XML Document Error

5. Click menu File > Save As to save the modified XML document as c:\herong\first_html_xsd_invalid.xml.

XMLPad seems to be a good tool to debug XSD validation error with this error line highlight feature.

Last update: 2013.

Table of Contents

 About This Book

 Introduction to XML Schema

XML Editor and Schema Processor - XMLPad

 Installing WMHelp XMLPad Pro

 Creating and Editing XML Documents

 Creating and Editing XML Schema Documents

 Assigning XML Schema to XML Documents

 Validating XML Documents with Assigned XSD

Validating Non-Conforming XML Documents

 XMLPad Crash When Validating Non-Conforming XML Documents

 Generating XML Schema Diagrams

 Generating XML Schema Documentations

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

 Xerces2 Java Parser - Java API of XML Parsers

 Using Xerces2 Java API

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

 "string" and Its Derived Datatypes

 "decimal" and Its Derived Datatypes

 "dateTime" and Its Related Datatypes

 Miscellaneous Built-in Datatypes

 Facets, Constraining Facets and Restriction Datatypes

 "simpleType" - Defining Your Own Simple Datatypes

 Complex Element Declaration

 Identity-Constraints: unique, key and keyref

 Assertion as Custom Validation Rules

 XML Schema Location and Namespace in XML Documents

 Overriding Element Types in XML Documents

 Linking Multiple Schema Documents Together

 Glossary

 References

 PDF Printing Version

Validating Non-Conforming XML Documents - Updated in 2014, by Dr. Herong Yang