Developer87
Developer87

Reputation: 2708

How to switch to XSD 1.1 from 1.0?

I've got following header in my xsd config:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns="http://www.mycompany.com/schema/app"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.mycompany.com/schema/app"
           elementFormDefault="qualified">

What do I need to switch to XSD 1.1 ?

There is a need to start using the <xs:assert/> tag.

Upvotes: 7

Views: 10340

Answers (2)

elmor
elmor

Reputation: 310

I believe the version attribute in the root schema element is to be used for the version of your organization's namespaced schema, not for the version of XML Schema.

If you want to indicate the W3C XML Schema standard version in the schema, use: xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" and then vc:minVersion="1.1" in the root schema tag.

In XML document instances, a header of <?xml version="1.1"?>, before the root element, is used to indicate the XML conforms to a newer version of XML with better language support and other features (see W3C XML 1.1 spec).

Upvotes: 1

Mathias M&#252;ller
Mathias M&#252;ller

Reputation: 22647

EDIT: this answer was wrong for 6 years. I initially claimed that adding the version attribute declares that a schema adheres to the XML Schema 1.1 standard. However, this attribute has nothing to do with the XSD version, it can be used for any arbitrary user-defined versioning.

I have now removed the false information.


Indicating that your XML Schema document adheres to the XML Schema 1.1 specification means adding the following to the outermost element:

  • Define the namespace for XML Schema versioning: xmlns:vc=http://www.w3.org/2007/XMLSchema-versioning
  • add the attribute vc:minVersion = "1.1"

Here is an example for the xs:schema element:

<xs:schema xmlns="http://www.mycompany.com/schema/app"
       xmlns:xs="http://www.w3.org/2001/XMLSchema"
       targetNamespace="http://www.mycompany.com/schema/app"
       elementFormDefault="qualified"
       xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
       vc:minVersion="1.1">

Even if you add this information your schema processor might not be capable of processing XSD 1.1 constructs like assertions, and indicating version 1.1 does not magically enable 1.1 processing.

Put another way, "switching" to XSD 1.1 does not mean mentioning the version in your xs:schema element, it means making sure your schema processor understands XML Schema 1.1. To find out, simply include an xs:assert element in the schema and check if you get any error messages. Perhaps there is a setting for the schema version in your tool, as there is in Oxygen:

enter image description here

See the Oxygen documentation for more ways to set the XML schema version.

By the way: if XSD 1.1 is not supported, there might still be support for Schematron - a language that is very useful for assertions and similar rules.

Upvotes: 8

Related Questions