7

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.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
Developer87
  • 2,448
  • 4
  • 23
  • 43

2 Answers2

8

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.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
  • The version attribute is for the version # of your schema, not to indicate the version of W3C XSD being used. – elmor Jan 27 '22 at 20:51
  • Thanks for your comment @elmor! Yes, this answer is indeed wrong. I believe I can edit the answer to improve it rather than deleting it, since there is extra information (e.g. if XSD 1.1 cannot be used, Schematron might be supported which also has assertions). – Mathias Müller Jan 29 '22 at 09:36
  • thank you for the edit. Your answer is perfect now! I up-voted it. :) – elmor Jan 30 '22 at 12:36
1

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).

elmor
  • 310
  • 1
  • 17
  • This answer correctly describes how to indicate the version of the XML Schema standard in an XSD document (+1!). However, I think the `version` information in an XML declaration does not describe which version of the XML Schema standard should be used to write a schema for this XML document. – Mathias Müller Jan 29 '22 at 09:45
  • @Mathias Müller: thank you; I corrected my statement about XML 1.1 above. You are correct, that it has nothing to do with XSD conformance. – elmor Jan 30 '22 at 12:32