∟"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:
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.
-->
<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:
c:\Progra~1\Java\jdk1.7.0_07\bin\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