XSD Tutorials - Herong's Tutorial Examples - v5.23, by 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:
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) 2002-2013 HerongYang.com. All Rights Reserved. --> <xs:element name="AnySimpleType_Datatype_Test"> <xs:complexType> <xs:sequence> <xs:element name="AnySimpleType" type="xs:anySimpleType" maxOccurs="unbounded"/> <xs:element name="Attribute_Test" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="AnySimpleType" type="xs:anySimpleType"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
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) 2002-2013 HerongYang.com. All Rights Reserved. --> <AnySimpleType_Datatype_Test> <!-- 4 valid "anySimpleType" representations as element contents --> <AnySimpleType> Everything is valid! </AnySimpleType> <AnySimpleType> 1971-05-16T00:00:01 </AnySimpleType> <AnySimpleType> 头 </AnySimpleType> <AnySimpleType><![CDATA[ Hello <b>Herong</b>! ]]> </AnySimpleType> <!-- 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=" 头 "/> </AnySimpleType_Datatype_Test>
If you validate the same example XML document with sample XSD document with Java tool, you will see 1 error for the invalid element:
herong> java XsdSchemaValidator ^^^ anySimpleType_datatype_test.xsd anySimpleType_datatype_test.xml Error: 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
Table of Contents
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
►Introduction of XSD Built-in Datatypes
Overview of XSD 1.1 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
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