"QName" Datatype Values and Representations

This section describes the built-in primitive datatype, 'QName' that represents XML element and attribute names with or without namespaces. Leading and trailing whitespaces are allowed and trimmed.

"QName" is a built-in datatype that represents (namespace URI, local name) pairs used as XML element and attribute names with these rules:

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

<?xml version="1.1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- QName_datatype_test.xsd
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<xs:element name="QName_Datatype_Test">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="QName" type="xs:QName" 
         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"?>
<!-- QName_datatype_test.xml
 - Copyright (c) 2013, HerongYang.com, All Rights Reserved.
-->
<QName_Datatype_Test xmlns:hy="herongyang.com">

<!-- 3 valid "QName" elements -->
  <QName>    schema   </QName>
  <QName>    hy:Tutorial   </QName>
  <QName>    hy:&#x5934;   </QName>

<!-- 3 invalid "QName" elements -->
  <QName>    2ndOption   </QName>
  <QName>    xs:schema   </QName>
  <QName>    hy:hy:any   </QName>
</QName_Datatype_Test>

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

c:\Progra~1\Java\jdk1.7.0_07\bin\java XsdSchemaValidator 
   QName_datatype_test.xsd QName_datatype_test.xml

Error:
   Line number: 13
   Column number: 34
   Message: cvc-datatype-valid.1.2.1: '2ndOption' is not a valid value
   for 'QName'. (Numeric digits not allowed as the leading character)

Error:
   Line number: 13
   Column number: 34
   Message: cvc-type.3.1.3: The value '    2ndOption   ' of element 
   'QName' is not valid.

Error:
   Line number: 14
   Column number: 34
   Message: UndeclaredPrefix: Cannot resolve 'xs:schema' as a QName: 
   the prefix 'xs' is not declared. ("xs" must be declared)

Error:
   Line number: 14
   Column number: 34
   Message: cvc-type.3.1.3: The value '    xs:schema   ' of element 
   'QName' is not valid.

Error:
   Line number: 15
   Column number: 34
   Message: cvc-datatype-valid.1.2.1: 'hy:hy:any' is not a valid 
   value for 'QName'. (Maximum 1 ":" allowed)

Error:
   Line number: 15
   Column number: 34
   Message: cvc-type.3.1.3: The value '    hy:hy:any   ' of element
   'QName' is not valid.

Failed with errors: 6

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