dom.GetElementsByTagName and dom.Writer

This section provides tutorial examples on how to use sample programs dom.GetElementsByTagName and dom.Writer to validate XML documents with XSD schema.

You can also try the other 2 DOM technology sample programs. They all support XSD schema validation:

Here is my test result:

herong> java_xerces dom.GetElementsByTagName -v -s hello_xsd_invalid.xml

[Error] hello_xsd_invalid.xml:4:24: cvc-type.3.1.2: Element 'p' is a
^^^ simple type, so it must have no element information item
^^^ [children].

<p xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
^^^ xsi:noNamespaceSchemaLocation="hello.xsd">
<i>

herong> java_xerces dom.Writer -v -s hello_xsd_invalid.xml

[Error] hello_xsd_invalid.xml:4:24: cvc-type.3.1.2: Element 'p' is a
^^^ simple type, so it must have no element information item
^^^ [children].

<?xml version="1.0" encoding="UTF-8"?>
<p xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
^^^ xsi:noNamespaceSchemaLocation="hello.xsd">
Hello <i>world</i>!</p>

Both dom.GetElementsByTagName and dom.Writer report XSD schema validation errors correctly. But errors are reported before the print out of the XML document information. This is because they are using the DOM technology, which builds the entire XML document object first before applying any validations.

Table of Contents

 About This Book

 Introduction to XML Schema

 XML Editor and Schema Processor - XMLPad

 Java API for XML Processing - JAXP

 JAXP - XML Schema (XSD) Validation

Xerces2 Java Parser - Java API of XML Parsers

 Installing Xerces2 Java Parser for XSD 1.1

 Verify Installation of Xerces2

 Xerces2 Sample Program List

 Xerces2 Sample Program dom.Counter

 dom.Counter Validating XML with Associated XSD

dom.GetElementsByTagName and dom.Writer

 sax.DocumentTracer and sax.Writer

 Examples of XSD and XML Files with Errors

 sax.Writer Reporting Errors Embedded in XML Structure

 XSD 1.1 not Supported by sax.Writer

 XSD 1.1 Supported by jaxp.SourceValidator

 Examples of XSD 1.1 and XML Files with Errors

 jaxp.TypeInfoWriter as an XSD 1.1 Validation Tool

 Using Xerces2 Java APIs

 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

 Archived Tutorials

 References

 Full Version in PDF/EPUB