XML Editor in VS2005: Support for inline schemas

The XML Editor provides support for Inline Schemas. Inline schemas are XML schema definitions included inside XML instance documents. They can be used to validate that the rest of the XML matches the schema constraints in the same way that external schema documents can be used. Likewise, the syntax and semantics of inline schemas are the same as for external schemas. Inline schemas can be useful in a number of situations, including:

· An architecture where internal DTDs were used and the developers wish to preserve that design pattern.

· It is difficult to access external files or URLs, e.g. for security or platform reasons.

· There is too much diversity in the set of schemas and instances that a system must process, so it is easiest to simply keep the schema as an integral part of the XML document.

The following XML snippet contains an example of using an inline schema.

<?xml version="1.0" encoding="utf-8"?>

<root xmlns:inl="https://inline">

  <xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema"

             targetNamespace="https://inline"

             xmlns="https://inline"

             elementFormDefault="qualified"

             attributeFormDefault="unqualified">

    <xs:element name="parent">

      <xs:complexType>

        <xs:sequence>

          <xs:element name="child" type="xs:string"/>

        </xs:sequence>

      </xs:complexType>

    </xs:element>

  </xs:schema>

 

  <inl:parent>

    <inl:child>text</inl:child>

  </inl:parent>

</root>

You can change the inline schema and the XML Editor will pick up those changes immediately and use the updated schema for validation and intellisense. For example, if you change the <child> element’s type from xs:string to xs:int, you will get a validation error.