Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Schemas

Using Inline Schemas

Instead of using an external schema file, MSXML version 3.0 or later allows you to use inline schemas. These schemas are useful when it is inconvenient to physically separate the schema and the instance (XML document). For example, if you generate XML-Data Reduced (XDR) schema from data retrieved from a database, it may be more convenient to put the schema and the data in the same file.

Note   Inline schemas are not supported in MSXML 2.5 and earlier versions. To avoid an error on the root element, use the Xmlinst.exe Replace Mode Tool.

Example

The following XML document contains an inline schema against which the Student element is validated. The name of the schema, mySchema, is indicated through the name attribute on the Schema element.

<Root>
<Schema name="mySchema" xmlns="urn:schemas-microsoft-com:xml-data"
             xmlns:dt="urn:schemas-microsoft-com:datatypes">
   <ElementType name="age" dt:type="int"/>
   <ElementType name="Student" model="closed" content="eltOnly">
     <element type="age"/>
   </ElementType>
</Schema>

Data file

<a:Student xmlns:a="x-schema:#mySchema">
   <a:age>10</a:age>
</a:Student>
</Root>

An element is associated with an inline schema just as it is with an external schema, through the "x-schema:" syntax when defining that element's namespace identifier. For an external schema, the URI or URL that follows "x-schema:" indicates the location of the external schema file. With an inline schema, that which follows "x-schema:" indicates the name of the schema within the XML instance document (indicated by the # sign followed by the name).

The "#" syntax following "x-schema:" refers to a schema within the local document only. This syntax cannot be used to reference a schema within an external document. For example, "x-schema:URI#name" is not allowed.

The inline schema associated with an element must precede that element within the document. When validating against a schema, if the name indicated through an element's namespace declaration does not correspond to an already parsed schema, an error will occur. An error will also occur when an element is associated with a schema that does not exist.

Inline Schemas Persisted from ADO

You can use MSXML 3.0 to parse inline schemas produced by Microsoft ActiveX® Data Objects (ADO), but they will not be validated.

Example

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
   xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
   xmlns:rs='urn:schemas-microsoft-com:rowset'
   xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
   <s:ElementType name='row'>
      <s:attribute type='CustomerID'/>
      <s:extends type='rs:rowbase'/>
   </s:ElementType>
<s:AttributeType name='CustomerID' rs:number='1'
   rs:nullable='true' rs:write='true'>
   <s:datatype dt:type='string' dt:maxLength='5'/>
</s:AttributeType>
</s:Schema>
<rs:data>
   <z:row CustomerID='…'/>
</rs:data>
</xml>

MSXML 3.0 essentially ignores the following elements and attributes, and the remainder of the schema is parsed as if it were a valid schema.

Elements Attributes
extends dt:max
  dt:maxExclusive
  dt:maxLength
  dt:min
  dt:minExclusive

Validation against the remainder of the schema cannot occur because the schema does not contain a name attribute and because the reference to the schema is not prefaced by "x-schema:". MSXML 3.0 views that reference as a Uniform Resource Name (URN) with no special significance.

See Also

definition Property | validateOnParse Property