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

"NOTATION" Datatype Values and Representations

This section describes the built-in primitive datatype, 'NOTATION' that represents custom defined notations to describe non-XML data formats. Whitespaces are allowed and removed.

"NOTATION" is a built-in datatype that represents custom defined notations to describe non-XML data formats with these rules:

  • The value space of "NOTATION" contains all notations defined in the XSD document.
  • The lexical space of "NOTATION" contains all notation names defined in the XSD document.
  • Leading and trailing whitespaces allowed and trimmed.
  • "NOTATION" datatype must be used indirectly through an "enumeration" custom datatype constructed from the "NOTATION" datatype.

To verify these rules, I wrote the first XSD document trying to use "NOTATION" directly:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- NOTATION_datatype_test_invalid_1.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="NOTATION_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="NOTATION" type="xs:NOTATION" 
         maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:notation name="jpg" public="image/jpeg" system="PViewer.exe"/>
<xs:notation name="gif" public="image/gif" system="PViewer.exe"/>
<xs:notation name="wav" public="audio/x-wav" system="MPlayer.exe"/>
</xs:schema>

Running my XsdSchemaValidator.java program presented earlier in the book, I get this error:

c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator 
   NOTATION_datatype_test_invalid_1.xsd any.xml

org.xml.sax.SAXParseException; systemId: 
file:/C:/herong/NOTATION_datatype_test_invalid_1.xsd; 
lineNumber: 10; columnNumber: 30;
enumeration-required-notation: The NOTATION type, 'NOTATION' used by 
element 'NOTATION', must have an enumeration facet value which 
specifies the notation elements used by this type.

java.lang.NullPointerException

In the second XSD document, I tried to construct an "enumeration" custom datatype based on "NOTATION" referring to an undefined notation name:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- NOTATION_datatype_test_invalid_2.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="NOTATION_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="NOTATION" maxOccurs="unbounded">
        <xs:simpleType>
          <xs:restriction base="xs:NOTATION">
            <xs:enumeration value="jpg"/>
            <xs:enumeration value="gif"/>
            <xs:enumeration value="doc"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:notation name="jpg" public="image/jpeg" system="PViewer.exe"/>
<xs:notation name="gif" public="image/gif" system="PViewer.exe"/>
<xs:notation name="wav" public="audio/x-wav" system="MPlayer.exe"/>
</xs:schema>

This time XsdSchemaValidator.java gives a different error:

c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator 
   NOTATION_datatype_test_invalid_2.xsd any.xml

org.xml.sax.SAXParseException; systemId: 
file:/C:/herong/NOTATION_datatype_test_invalid_2.xsd; 
lineNumber: 14; columnNumber: 42;
src-resolve: Cannot resolve the name 'doc' to a(n) 'notation' 
component.

java.lang.NullPointerException

In the third XSD document, I fixed the error and get a valid schema now:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- NOTATION_datatype_test_valid.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="NOTATION_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="NOTATION" maxOccurs="unbounded">
        <xs:simpleType>
          <xs:restriction base="xs:NOTATION">
            <xs:enumeration value="jpg"/>
            <xs:enumeration value="gif"/>
            <xs:enumeration value="wav"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:notation name="jpg" public="image/jpeg" system="PViewer.exe"/>
<xs:notation name="gif" public="image/gif" system="PViewer.exe"/>
<xs:notation name="wav" public="audio/x-wav" system="MPlayer.exe"/>
</xs:schema>

Here is a sample XML document that can be used to test this XSD document:

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

<!-- 3 valid "NOTATION" elements -->
  <NOTATION>    jpg   </NOTATION>
  <NOTATION>    wav   </NOTATION>

<!-- 3 invalid "NOTATION" elements -->
  <NOTATION>    mp3   </NOTATION>
</NOTATION_Datatype_Test>

When validating this XML document with my XsdSchemaValidator.java program, I get 1 group of errors for 1 invalid XML element:

c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator 
   NOTATION_datatype_test_valid.xsd NOTATION_datatype_test.xml

Error:
   Line number: 12
   Column number: 34
   Message: cvc-enumeration-valid: Value 'mp3' is not facet-valid with
   respect to enumeration '[jpg, gif, wav]'. It must be a value from 
   the enumeration.

Error:
   Line number: 12
   Column number: 34
   Message: cvc-type.3.1.3: The value '    mp3   ' of element 
   'NOTATION' is not valid.

Failed with errors: 2

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 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

 "anyURI" Datatype Values and Representations

 "QName" Datatype Values and Representations

"NOTATION" Datatype Values and Representations

 "base64Binary" Datatype Values and Representations

 "hexBinary" Datatype Values and Representations

 "float" and "double" Datatype Values and Representations

 "boolean" Datatype Values and Representations

 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

"NOTATION" Datatype Values and Representations - Updated in 2014, by Dr. Herong Yang