"anyURI" Datatype Values and Representations

This section describes the built-in primitive datatype, 'anyURI' that represents IRI (Internationalized Resource Identifier) values. Leading and trailing whitespaces are allowed and trimmed.

"anyURI" is a built-in datatype that represents URI values as defined in "RFC3987 - Internationalized Resource Identifiers (IRIs)" with these rules:

Note that IRI supports right-to-left writings. So: "mus#321=dis?lmth.xedni/DSX/moc.gnaygnoreh//:ptth" is a valid "anyURI" representation.

To verify these rules, I wrote this simple XSD document that uses "anyURI" datatype to declare XML elements:

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- anyURI_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="AnyURI_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="AnyURI" type="xs:anyURI" 
         maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

Here is a sample XML document that can be used to test these declarations:

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

<!-- 8 valid "AnyURI" elements -->
  <AnyURI>    mailto:herong_yang@yahoo.com   </AnyURI>
  <AnyURI>    http://www.herongyang.com/XSD/    </AnyURI>
  <AnyURI>    *.herongyang.com/*    </AnyURI>
  <AnyURI>    XSD_1_1_Built_in_Datatype.jpg    </AnyURI>
  <AnyURI>    anystring:anys_tring?any/string#anystring   </AnyURI> 
  <AnyURI>http://herongyang.com/XSD/index.html?sid=123#sum</AnyURI>
  <AnyURI>mus#321=dis?lmth.xedni/DSX/moc.gnaygnoreh//:ptth</AnyURI>
  <AnyURI>    space allowed ?   </AnyURI>

<!-- 2 invalid "AnyURI" elements -->
  <AnyURI>    any_string:anystring   </AnyURI>
  <AnyURI>    any@string:http   </AnyURI>
</AnyURI_Datatype_Test>

When validating this XML document with my XsdSchemaValidator.java program presented earlier in the book, I get 2 groups of errors for 2 invalid XML elements:

c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator 
   anyURI_datatype_test.xsd anyURI_datatype_test.xml
   
Error:
   Line number: 18
   Column number: 47
   Message: cvc-datatype-valid.1.2.1: 'any_string:anystring' is not 
   a valid value for 'anyURI'.

Error:
   Line number: 18
   Column number: 47
   Message: cvc-type.3.1.3: The value '    any_string:anystring   '
   of element 'AnyURI' is not valid.

Error:
   Line number: 19
   Column number: 42
   Message: cvc-datatype-valid.1.2.1: 'any@string:http' is not a valid
   value for 'anyURI'.

Error:
   Line number: 19
   Column number: 42
   Message: cvc-type.3.1.3: The value '    any@string:http   ' of 
   element 'AnyURI' is not valid.

Failed with errors: 4

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

 "string" and Its Derived Datatypes

 "decimal" and Its Derived Datatypes

 "dateTime" and Its Related Datatypes

Miscellaneous Built-in Datatypes

"anyURI" Datatype Values and Representations

 "QName" Datatype Values and Representations

 "NOTATION" Datatype Values and Representations

 "base64Binary" Datatype Values and Representations

 "hexBinary" Datatype Values and Representations

 "float" and "double" Datatype Values and Representations

 "boolean" Datatype Values and Representations

 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

 Glossary

 References

 PDF Printing Version