∟"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:
The value space of "anyAtomicType" is all possible simple values,
which strings of characters treated as atomic values, not list of values separated by whitespaces.
Complex values (XML structures) are not valid "anyAtomicType" values.
The lexical space of "anyAtomicType" is the same as the value space.
An "anyAtomicType" lexical representation is parsed to an "anyAtomicType" value
by taking the representation as is.
"anyAtomicType" 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 <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) 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> 头 </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=" 头 "/>
</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 1.7.
c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator
anyAtomicType_datatype_test.xsd anyAtomicType_datatype_test.xml
org.xml.sax.SAXParseException; systemId:
file:/C:/heronganyAtomicType_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,
I get the correct result.
c:\Progra~1\Java\jdk1.7.0_07\bin\java
-cp ".;c:\local\xerces-2_11_0-xml-schema-1.1-beta\xercesImpl.jar;
c:\local\xerces-2_11_0-xml-schema-1.1-beta
\org.eclipse.wst.xml.xpath2.processor_1.1.0.jar"
Xsd11SchemaValidator
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