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

"anySimpleType" Built-in Datatype Values and Representations

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

The second special built-in datatype to study is "anySimpleType".

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

  • The value space of "anySimpleType" is all possible simple values (strings of characters). Complex values (XML structures) are not valid "anySimpleType" values.
  • The lexical space of "anySimpleType" is the same as the value space.
  • An "anySimpleType" lexical representation is parsed to an "anySimpleType" value by taking the representation as is.
  • "anySimpleType" 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">
<!-- anySimpleType_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
<xs:element name="AnySimpleType_Datatype_Test">
      <xs:element name="AnySimpleType" type="xs:anySimpleType" 
      <xs:element name="Attribute_Test" maxOccurs="unbounded">
          <xs:attribute name="AnySimpleType" type="xs:anySimpleType"/>

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

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

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

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


If you validate the same example XML document with sample XSD document with Java tool, you will see 1 error for the invalid element:

c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator 
   anySimpleType_datatype_test.xsd anySimpleType_datatype_test.xml
   Line number: 15
   Column number: 67
   Message: cvc-type.3.1.2: Element 'AnySimpleType' 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

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