http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Download
Installation
Build Instructions

API Docs
Samples
Schema

FAQs
Programming
Migration

Releases
Bug-Reporting
Feedback

Y2K Compliance
PDF Document

CVS Repository
Mail Archive

Introduction
 

This package contains an implementation of the W3C XML Schema Language, a recommendation of the Worldwide Web Consortium available in three parts: XML Schema: Primer and XML Schema: Structures and XML Schema: Datatypes. We consider this implementation complete except for the limitations cited below.

We would very much appreciate feedback on the package via the Xerces-C mailing list xerces-c-dev@xml.apache.org , and we encourage the submission of bugs as described in Bug-Reporting page. Please read this document before using this package.


Limitations
 
  • No interface is provided for exposing the post-schema validation infoset , beyond that provided by DOM or SAX;
  • The parser permits situations in which there is circular or multiple importing. However, the parser only permits forward references--that is, references directed from the direction of the schema cited in the instance document to other schemas. For instance, if schema A imports both schema B and schema C, then any reference in schema B to an information item from schema C will produce an error. Circular or multiple <include>s have similar limitations.
  • Due to the way in which the parser constructs content models for elements with complex content, specifying large values for the minOccurs or maxOccurs attributes may cause a stack overflow or very poor performance in the parser. Large values for minOccurs should be avoided, and unbounded should be used instead of a large value for maxOccurs.

Interpretation of Areas that are Unclear or Implementation-Dependent
 
  • We have interpreted the specs as requiring <keyref> Identity Constraints to refer to <key> or <unique> identity constraints within the scope of the elements to which the <keyref> is attached. This interpretation is at variance with the Schema Primer, which contains an example with a <keyref> declared on an element used inside the element of its corresponding <key>.

Usage
 

Here is an example how to turn on schema processing in DOMParser (default is off). Note that you must also turn on namespace support (default is off) for schema processing.

// Instantiate the DOM parser.
DOMParser parser;
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.parse(xmlFile);

Usage in SAXParser is similar, please refer to the sample program 'samples/SAXCount/SAXCount.cpp' for further reference.

Here is an example how to turn on schema processing in SAX2XMLReader (default is on). Note that namespace must be on (default is on) as well.

SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLString::transcode("http://xml.org/sax/features/namespaces"), true);
parser->setFeature(XMLString::transcode("http://apache.org/xml/features/validation/schema"), true);
parser->parse(xmlFile);

Review the sample file, 'samples/data/personal-schema.xml' and 'samples/data/personal.xsd' for an example of an XML Schema grammar.


Assocating Schema Grammar with instance document
 

Schema grammars can be associated with instance documents in two ways.

Specifying Schema Grammar through method calls:
 

An application developer may use the methods setExternalSchemaLocation if they use namespaces, and setExternalNoNamespaceSchemaLocation otherwise to associate schemas with instance documents. (For SAX2XMLReader, use the properites: "http://apache.org/xml/properties/schema/external-schemaLocation" and "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation")

Here is an example with no target namspace:

// Instantiate the DOM parser.
DOMParser parser;
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.setExternalNoNamespaceSchemaLocation("personal.xsd");
parser.parse("test.xml");

// Instantiate the SAX2 XMLReader.
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setProperty(
       XMLString::transcode("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation"),
       XMLString transcode("personal.xsd"));
parser.parse("test.xml");

Here is an example with a target namespace. Note that it is an error to specify a different namespace than the target namespace defined in the Schema.

// Instantiate the DOM parser.
DOMParser parser;
parser.setDoNamespaces(true);
parser.setDoSchema(true);
parser.setExternalSchemaLocation("http://my.com personal.xsd http://my2.com test2.xsd");
parser.parse("test.xml");

// Instantiate the SAX2 XMLReader.
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setProperty(
       XMLString::transcode("http://apache.org/xml/properties/schema/external-SchemaLocation"),
       XMLString transcode("http://my.com personal.xsd http://my2.com test2.xsd"));
parser.parse("test");

Specifying Schema Grammar through attributes in the instance document:
 

If schema grammar was not specified externally through methods, then each instance document that uses XML Schema grammars must specify the location of the grammars it uses by using an xsi:schemaLocation attribute if they use namespaces, and xsi:noNamespaceSchemaLocation attribute otherwise.

Here is an example with no target namspace:

<?xml version="1.0" encoding="UTF-8"?>
<personnel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:noNamespaceSchemaLocation='personal.xsd'>
...
</personnel>

Here is an example with a target namespace. Note that it is an error to specify a different namespace than the target namespace defined in the Schema.

<?xml version="1.0" encoding="UTF-8"?>
<personnel xmlns="http://my.com"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:schemaLocation="http://my.com personal.xsd">
...
</personnel>



Copyright © 2001 The Apache Software Foundation. All Rights Reserved.