title: Using entity 'constants' in an XML Schema
body: <p>I am trying to create an XML schema in which a lot of types are sharing some 'magic numbers'.</p>
  
  <p>Instead of having to change my schema in several locations if/when these magic numbers change, I would like to pull them out into some kind of constant definition.</p>
  
  <p>I have played around with adding a DTD to my schema and declaring some entities here. But I am by no means an expert on DTD, and while it seems to work in a C# application that uses the schema, there is also a native Win32 application that uses the same schema with msxml 4.0 where this blows up...</p>
  
  <p>Does anyone have experience with extending the schema definition this way (can it be done), or is there a better way?</p>
  
  <p>(EDIT: An example)</p>
  
  <p>Example XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE schema [
     &lt;!ENTITY SomeMagicNumber "10"&gt;]&gt;
  &lt;xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
             elementFormDefault="qualified"
             xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
             xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
    &lt;xs:simpleType name="MySimpleType"&gt;
      &lt;xs:restriction base="xs:int"&gt;
        &lt;xs:maxInclusive value="&amp;SomeMagicNumber;" /&gt;
      &lt;/xs:restriction&gt;
    &lt;/xs:simpleType&gt;
  
    &lt;xs:complexType name="MyIntegers"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="value" type="xs:int" maxOccurs="&amp;SomeMagicNumber;" /&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="MyFloats"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="value" type="xs:float" maxOccurs="&amp;SomeMagicNumber;" /&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Example Delphi Win32 code to load the schema:</p>
  
  <pre><code>var
    XmlSchemas: IXMLDOMSchemaCollection;
    XmlSchema: IXMLDOMDocument2;
    XmlDocument: IXMLDOMDocument2;
  begin
    XmlSchemas := CoXMLSchemaCache40.Create;
  
    XmlSchema := CoDOMDocument40.Create;
    XmlSchema.load((*INSERT SCHEMA PATH HERE*));
    Assert(XmlSchema.parseError.errorCode = 0, XmlSchema.parseError.reason);
    XmlSchemas.add((*INSERT SCHEMA TARGET NAMESPACE HERE*), XmlSchema);
  
    XmlDocument := CoDOMDocument40.Create;
    XmlDocument.schemas := XmlSchemas;
    XmlDocument.validateOnParse := True;
  end;
  </code></pre>
  
  <p>The code asserts after attempting to load the schema. Reason: 'The name of the top most element must match the name of the DOCTYPE declaration.'</p>