"ENTITY" Datatype Values and Representations

This section describes the built-in datatype 'ENTITY' designed to support user defined and unparsed external XML entities. 'ENTITY' datatype is derived from 'NCName'.

In order to support some XML document special features, 3 built-in datatypes are derived from "NCName": "ENTITY", "ID" and "IDREF".

"ENTITY" is a datatype derived from "NCName" datatype by limiting its value to names of user defined unparsed external XML entities.

Note that XML entities can not be defined in XSD document. They must be defined in the DTD (Document Type Definition) format embedded in or assigned to the XML document. Here is an example of a DTD statement that defines an unparsed external XML entity called "site-logo":

<!ENTITY site-logo SYSTEM "logo.gif" NDATA gif>

Here is a sample XSD document that defines a sub element <ENTITY> to use "ENTITY" values:

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

Here is a sample XML document that contains <ENTITY> elements to test that definition:

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

<!DOCTYPE ENTITY_Datatype_Test [
  <!ENTITY site-logo SYSTEM "logo.gif" NDATA gif>
  <!ENTITY cover.photo SYSTEM "sunrise.jpg" NDATA jpeg>
  <!ENTITY stdin SYSTEM "input.dat" NDATA data>
  <!ENTITY std:out SYSTEM "output.dat" NDATA data>
  <!ENTITY footer SYSTEM "/boilerplate/footer.xml">
  <!ENTITY quot "&#x22;">
]>

<ENTITY_Datatype_Test>
<!-- 3 valid "ENTITY" elements -->
  <ENTITY>    site-logo </ENTITY>
  <ENTITY>  cover.photo </ENTITY>
  <ENTITY>  stdin       </ENTITY>

<!-- 5 valid "ENTITY" elements -->
  <ENTITY>  bg-image    </ENTITY>
  <ENTITY>  std:out     </ENTITY>
  <ENTITY>    footer    </ENTITY>
  <ENTITY>      quot    </ENTITY>
  <ENTITY>       amp    </ENTITY>
</ENTITY_Datatype_Test>

Notes on this example XML document, entity_datatype_test.xml:

If you run JDK tool XsdSchemaValidator.java on this test, you will see 5 groups of errors for the last 5 invalid elements.

herong> java XsdSchemaValidator
^^^ entity_datatype_test.xsd entity_datatype_test.xml

Error:
   Line number: 22
   Column number: 34
   Message: UndeclaredEntity: Entity 'bg-image' is not declared.

Error:
   Line number: 22
   Column number: 34
   Message: cvc-type.3.1.3: The value '  bg-image    ' of element
   'ENTITY' is not valid.

Error:
   Line number: 23
   Column number: 34
   Message: cvc-datatype-valid.1.2.1: 'std:out' is not a valid value
   for 'NCName'.

Error:
   Line number: 23
   Column number: 34
   Message: cvc-type.3.1.3: The value '  std:out     ' of element
   'ENTITY' is not valid.

Error:
   Line number: 24
   Column number: 34
   Message: UndeclaredEntity: Entity 'footer' is not declared.

Error:
   Line number: 24
   Column number: 34
   Message: cvc-type.3.1.3: The value '    footer    ' of element
   'ENTITY' is not valid.

Error:
   Line number: 25
   Column number: 34
   Message: UndeclaredEntity: Entity 'quot' is not declared.

Error:
   Line number: 25
   Column number: 34
   Message: cvc-type.3.1.3: The value '      quot    ' of element
   'ENTITY' is not valid.

Error:
   Line number: 26
   Column number: 34
   Message: UndeclaredEntity: Entity 'amp' is not declared.

Error:
   Line number: 26
   Column number: 34
   Message: cvc-type.3.1.3: The value '       amp    ' of element
   'ENTITY' is not valid.

Failed with errors: 10

Note that you may have difficulties to validate this XML document with the XSD schema with other XML tools, because it has the embedded DTD statements.

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 APIs

 XML Schema Language - Basics

 Introduction of XSD Built-in Datatypes

"string" and Its Derived Datatypes

 "string" Datatype Values and Representations

 "normalizedString" Datatype Values and Representations

 "token" Datatype Values and Representations

 "language" Datatype Values and Representations

 "language" Datatype Values - Invalid Inputs

 "Name" Datatype Values and Representations

 "NMTOKEN" Datatype Values and Representations

 "NCName" Datatype Values and Representations

"ENTITY" Datatype Values and Representations

 "ID" Datatype Values and Representations

 "IDREF" Datatype Values and Representations

 "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

 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

 Archived Tutorials

 References

 Full Version in PDF/EPUB