I am trying to create an XML schema in which many types use some "magic numbers".
Instead of changing my scheme in several places if / when these magic numbers change, I would like to put them in some kind of constant definition.
I played with adding DTDs to my schema and declaring some objects here. But I am by no means a DTD specialist, and although it works in a C # application using a scheme, there is also a native Win32 application that uses the same scheme with msxml 4.0 where it explodes ...
Does anyone have experience expanding the definition of a schema this way (can this be done), or is there a better way?
(EDIT: example)
XML example:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE schema [ <!ENTITY SomeMagicNumber "10">]> <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"> <xs:simpleType name="MySimpleType"> <xs:restriction base="xs:int"> <xs:maxInclusive value="&SomeMagicNumber;" /> </xs:restriction> </xs:simpleType> <xs:complexType name="MyIntegers"> <xs:sequence> <xs:element name="value" type="xs:int" maxOccurs="&SomeMagicNumber;" /> </xs:sequence> </xs:complexType> <xs:complexType name="MyFloats"> <xs:sequence> <xs:element name="value" type="xs:float" maxOccurs="&SomeMagicNumber;" /> </xs:sequence> </xs:complexType> </xs:schema>
Delphi Win32 sample code for loading a schema:
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;
The code after trying to load the circuit is confirmed. Reason: 'The name of the top element must match the name of the DOCTYPE declaration.'
source share