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

Running XMLReaderValidator on XSD 1.1 Schema

This section provides a tutorial example on new built-in datatypes introduced in XSD 1.1 and on validating XSD 1.1 schema with the XMLReader class from Xerces2. 2.11.0.

The previous tutorial showed us how to use the XMLReader class in "Xerces2 2.11.0 (XML Schema 1.1) (Beta)" version to validate XML document again XSD document. But the XSD document used, dictionary.xsd, does not use any XSD 1.1 features.

In order to test XSD 1.1 features with "Xerces2 2.11.0 (XML Schema 1.1) (Beta)", I wrote this sample XSD document that uses 4 built-in datatypes introduced in XSD 1.1:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- xsd11_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="XSD11_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="AnyAtomicType" type="xs:anyAtomicType" 
        maxOccurs="unbounded"/>
      <xs:element name="DateTimeStamp" type="xs:dateTimeStamp" 
        maxOccurs="unbounded"/>
      <xs:element name="DayTimeDuration" type="xs:dayTimeDuration" 
        maxOccurs="unbounded"/>
      <xs:element name="YearMonthDuration" type="xs:yearMonthDuration" 
        maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Here is a sample XML document to test this XSD document:

<?xml version="1.1"?>
<!-- xsd11_datatype_test.xml
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->

<XSD11_Datatype_Test 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:noNamespaceSchemaLocation="xsd11_datatype_test.xsd">

<!-- 3 valid "anyAtomicType" representations -->
  <AnyAtomicType>   1971-05-16T00:00:01  </AnyAtomicType>
  <AnyAtomicType>   &#x5934;             </AnyAtomicType>
  <AnyAtomicType><![CDATA[   Hello <b>Herong</b>!   ]]>
  </AnyAtomicType>
 
<!-- 1 invalid "anyAtomicType" representations -->
  <AnyAtomicType>   Hello <b size="9">Herong</b>! </AnyAtomicType>

<!-- 1 valid "dateTimeStamp" representations -->
  <DateTimeStamp>   1971-05-16T00:00:01Z   </DateTimeStamp>

<!-- 1 invalid "dateTimeStamp" representations -->
  <DateTimeStamp>   &#x5934;      </DateTimeStamp>

<!-- 1 valid "dayTimeDuration" representations -->
  <DayTimeDuration>    P3DT5H20M30.123S  </DayTimeDuration>

<!-- 1 invalid "dayTimeDuration" representations -->
  <DayTimeDuration>   P1Y2M3DT5H20M30.123S    </DayTimeDuration>

<!-- 1 valid "yearMonthDuration" representations -->
  <YearMonthDuration>    P1Y2M  </YearMonthDuration>

<!-- 1 invalid "yearMonthDuration" representations -->
  <YearMonthDuration>   P1Y2M3DT5H20M30.123S    </YearMonthDuration>
</XSD11_Datatype_Test>

When running the XMLReader class tool, XMLReaderValidator.java, I get this error:

c:\Progra~1\Java\jdk1.7.0_07\bin\java
   -cp ".;c:\local\xerces-2_11_0-xml-schema-1.1-beta\xercesImpl.jar;
   c:\local\xerces-2_11_0-xml-schema-1.1-beta
   \org.eclipse.wst.xml.xpath2.processor_1.1.0.jar"
   XMLReaderValidator xsd11_datatype_test.xml

Error:
   Public ID: null
   System ID: file:///C:/herong/xsd11_datatype_test.xsd
   Line number: 10
   Column number: 29
   Message: src-resolve.4.2: Error resolving component 
   'xs:anyAtomicType'. It was detected that 'xs:anyAtomicType' is in
   namespace 'http://www.w3.org/2001/XMLSchema', but components from
   this namespace are not referenceable from schema document 
   'file:///C:/herong/xsd11_datatype_test.xsd'. If this is the 
   incorrect namespace, perhaps the prefix of 'xs:anyAtomicType' needs
   to be changed. If this is the correct namespace, then an 
   appropriate 'import' tag should be added to 
   'file:///F:/herong/xsd11_datatype_test.xsd'.

Error:
   Public ID: null
   System ID: file:///C:/herong/xsd11_datatype_test.xsd
   Line number: 10
   Column number: 29
   Message: src-resolve: Cannot resolve the name 'xs:anyAtomicType' 
   to a(n) 'type definition' component.

I am confused with this error. What does it mean that 'xs:anyAtomicType' is in the namespace, but components are not referenceable? See next tutorial for the answer.

Last update: 2013.

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

Using Xerces2 Java API

 XML Schema (XSD) Validation using XMLReader

 Running XMLReaderValidator with Xerces2 2.11.0 Beta

Running XMLReaderValidator on XSD 1.1 Schema

 XML Schema (XSD) Validation using SAXParser

 SAXParser for XSD Validation in JDK 1.7

 SAXParser for XSD 1.1 Validation

 Xsd11SchemaValidator.java for XSD 1.1 Validation

 Xsd11SchemaValidator.java XSD 1.1 Test Result

 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

Running XMLReaderValidator on XSD 1.1 Schema - Updated in 2014, by Dr. Herong Yang