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

"anyAtomicType" Built-in Datatype Values and Representations

This section provides a tutorial example to show built-in datatype 'anyAtomicType' valid values and representations. Everything, except XML structure, is a valid 'anyAtomicType' lexical representation.

The third special built-in datatype to study is "anyAtomicType".

"anyAtomicType" is a built-in datatype designed to be a wildcard datatype to represent any simple values with these rules:

  • The value space of "anyAtomicType" is all possible simple values, which strings of characters treated as atomic values, not list of values separated by whitespaces. Complex values (XML structures) are not valid "anyAtomicType" values.
  • The lexical space of "anyAtomicType" is the same as the value space.
  • An "anyAtomicType" lexical representation is parsed to an "anyAtomicType" value by taking the representation as is.
  • "anyAtomicType" is a simple type, it can be used to declare both XML elements and XML attributes.

To verify these rules, I wrote this simple XSD document:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- anyAtomicType_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
<xs:element name="AnyAtomicType_Datatype_Test">
      <xs:element name="AnyAtomicType" type="xs:anyAtomicType" 
      <xs:element name="Attribute_Test" maxOccurs="unbounded">
          <xs:attribute name="AnyAtomicType" type="xs:anyAtomicType"/>

With <AnyAtomicType> element and <AnyAtomicType> attribute are declared as "anyAtomicType", anything are valid representations except XML structures. Here is an XML document with some examples:

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

<!-- 4 valid "anyAtomicType" representations as element contents -->
  <AnyAtomicType>   Everything is valid! </AnyAtomicType>
  <AnyAtomicType>   1971-05-16T00:00:01  </AnyAtomicType>
  <AnyAtomicType>   &#x5934;             </AnyAtomicType>
  <AnyAtomicType><![CDATA[   Hello <b>Herong</b>!   ]]>
  <AnyAtomicType>id1 id2 id3 id4 id5</AnyAtomicType>
<!-- 1 invalid "anyAtomicType" representations as element contents -->
  <AnyAtomicType>   Hello <b size="9">Herong</b>! </AnyAtomicType>

<!-- 3 valid "anyAtomicType" representations as attribute values -->
  <Attribute_Test AnyAtomicType="   Everything is valid! "/>
  <Attribute_Test AnyAtomicType="   1971-05-16T00:00:01  "/>
  <Attribute_Test AnyAtomicType="   &#x5934;             "/>


If I validate the same example XML document with sample XSD document with Java tool, XsdSchemaValidator.java, I get an error. This is because "anyAtomicType" is a new built-in datatype introduced in XSD 1.1, which is not supported by JDK 1.7.

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

org.xml.sax.SAXParseException; systemId: 
file:/C:/heronganyAtomicType_datatype_test.xsd; lineNumber: 10; 
columnNumber: 29; 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/anyAtomicType_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 


If I switch to my XSD 1.1 version tool, Xsd11SchemaValidator.java, I get the correct result.

   -cp ".;c:\local\xerces-2_11_0-xml-schema-1.1-beta\xercesImpl.jar;
   anyAtomicType_datatype_test.xsd anyAtomicType_datatype_test.xml
   Line number: 18
   Column number: 67
   Message: cvc-type.3.1.2: Element 'AnyAtomicType' is a simple type, 
   so it must have no element information item [children].

Failed with errors: 1

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

 Overview of XSD 1.1 Built-in Datatypes

 List of Built-in Datatypes

 Datatypes, Values and Representations

 Datatypes, Values and Representations - Example

 Built-in Datatypes Lexical Representation Examples

 Declaring Elements and Attributes with Built-in Datatypes

 Defining New Datatypes with Built-in Datatypes

 "anyType" Built-in Datatype Values and Representations

 "anySimpleType" Built-in Datatype Values and Representations

"anyAtomicType" Built-in Datatype Values and Representations

 "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



 PDF Printing Version

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