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

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) 2002-2013 HerongYang.com. All Rights Reserved.
-->
<xs:element name="AnyAtomicType_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="AnyAtomicType" type="xs:anyAtomicType"
        maxOccurs="unbounded"/>
      <xs:element name="Attribute_Test" maxOccurs="unbounded">
        <xs:complexType>
          <xs:attribute name="AnyAtomicType" type="xs:anyAtomicType"/>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

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) 2002-2013 HerongYang.com. All Rights Reserved.
-->

<AnyAtomicType_Datatype_Test
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="anyAtomicType_datatype_test.xsd">
<!-- 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>
  <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;             "/>

</AnyAtomicType_Datatype_Test>

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.

herong> java XsdSchemaValidator
^^^ anyAtomicType_datatype_test.xsd anyAtomicType_datatype_test.xml

org.xml.sax.SAXParseException; systemId:
file:/C:/herong/anyAtomicType_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
'file:/F:/herong/anyAtomicType_datatype_test.xsd'.

java.lang.NullPointerException

If I switch to my XSD 1.1 version tool, Xsd11SchemaValidator.java with Xerces2 XML Schema 1.1 JAR files, I get the correct result.

herong> type java_xerces.bat
java -cp .;.\xerces-2_12_1-xml-schema-1.1\xml-apis.jar;
^^^.\xerces-2_12_1-xml-schema-1.1\xercesImpl.jar;
^^^.\xerces-2_12_1-xml-schema-1.1\serializer.jar;
^^^.\xerces-2_12_1-xml-schema-1.1\resolver.jar.jar;
^^^.\xerces-2_12_1-xml-schema-1.1\org.eclipse.wst.xml.xpath2.processor_1.2.0.jar;
^^^.\xerces-2_12_1-xml-schema-1.1\xercesSamples.jar; %1 %2 %3 %4 %5 %6

herong> java_xerces Xsd11SchemaValidator.java
^^^ anyAtomicType_datatype_test.xsd anyAtomicType_datatype_test.xml

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

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 APIs

 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

 Glossary

 Archived Tutorials

 References

 Full Version in PDF/EPUB