∟"anyType" Built-in Datatype Values and Representations
This section provides a tutorial example to show built-in datatype 'anyType' valid values and representations. Everything, including XML structure, is a valid 'anyType' lexical representation.
To fully understand built-in datatypes defined in XSD 1.1,
we need to spend time to read the specification and writing test XSD documents and XML documents
for each datatype. Let's start with the first special built-in datatype "anyType" in this section.
"anyType" is a built-in datatype designed to be a wildcard datatype
to represent any simple or complex values with these rules:
The value space of "anyType" is all possible simple values (strings of characters) and
all possible complex values (XML structures).
The lexical space of "anyType" is the same as the value space.
An "anyType" lexical representation is parsed to an "anyType" value by taking the representation as is.
This means that everything is valid in an "anyType" element.
"anyType" is a complex type, it can only be used to declare XML elements.
It is not allowed for declaring XML attributes.
To verify these rules, I wrote this simple XSD document:
To show you that "anyType" is not allowed for declaring XML attributes,
I wrote this invalid XSD document:
<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- anyType_datatype_invalid_test.xsd
- Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="AnyType_Datatype_Test">
<xs:complexType>
<xs:sequence>
<xs:element name="AnyType" type="xs:anyType"
maxOccurs="unbounded"/>
<xs:element name="Attribute_Test" maxOccurs="unbounded">
<xs:complexType>
<!-- "anyType" is a complex type.
It can not be used for attributes -->
<xs:attribute name="AnyType" type="xs:anyType"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
If you validate the same example XML document with this XSD document,
you will see this error:
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
anyType_datatype_invalid_test.xsd anytype_datatype_test.xml
org.xml.sax.SAXParseException; systemId:
anyType_datatype_invalid_test.xsd;
lineNumber: 16; columnNumber: 59; src-resolve:
Cannot resolve the name 'xs:anyType' to a(n)
'simpleType definition' component.
java.lang.NullPointerException