Intellij IDEA : How to validate XML SCHEMA 1

I am trying out XML SCHEMA 1.1 in IDEA 13.02 with JDK 7

This is an XML schema code I got from a tutorial. When I open this file in IntelliJ IDEA and click "Validate" , I get the following errors:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'openContent'. One of '{"http://www.w3.org/2001/XMLSchema":annotation, "http://www.w3.org/2001/XMLSchema":simpleContent, "http://www.w3.org/2001/XMLSchema":complexContent, "http://www.w3.org/2001/XMLSchema":group, "http://www.w3.org/2001/XMLSchema":all, "http://www.w3.org/2001/XMLSchema":choice, "http://www.w3.org/2001/XMLSchema":sequence, "http://www.w3.org/2001/XMLSchema":attribute, "http://www.w3.org/2001/XMLSchema":attributeGroup, "http://www.w3.org/2001/XMLSchema":anyAttribute}' is expected.

This is the XSD File using XML Schema 1.1 enhancements:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.books.org"
        xmlns:pub="http://www.books.org"
        elementFormDefault="qualified">

    <complexType name="Publication" abstract="true">
        <openContent mode="interleave">
            <any />
        </openContent>
        <sequence>
            <element name="Title" type="string" />
            <element name="Author" type="string" />
            <element name="Date" type="gYear"/>
        </sequence>
    </complexType>

    <complexType name="BookPublication">
        <complexContent>
            <extension base="pub:Publication">
                <openContent mode="none">
                </openContent>
                <sequence>
                    <element name="ISBN" type="string"/>
                    <element name="Publisher" type="string"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>

    <element name="BookStore">
        <complexType>
            <sequence>
                <element name="Book" type="pub:BookPublication" maxOccurs="unbounded" />
            </sequence>
        </complexType>
    </element>

</schema>

Is there a way to validate this or upgrade the validator used by IDEA ?


Try adding xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" and vc:minVersion="1.1" to <schema> :

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

It will inform IDEA that you are using a XSD 1.1 Schema.

I've used XSD 1.1 with WebStorm 8, which I believe uses the same parser as IDEA.


If your XML-validator supports XSD 1.0 and 1.1 (not only one version), but can't recognize version of XSD automatically, you need add attributes (like said @helderdarocha)

    xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" 
    vc:minVersion="1.1"

to "schema" tag and validator will know what version need use for check.

But if your XML-validator supports only XSD 1.0, you should remove unsupported items , it's the only way to be validated, reference to minVersion will not working.

As example:

  • XML Validator ".Net 4.0 (XSD 1.0)" will say about invalid document, no matter whether you have specified a minimum version;

  • XML Validator "Xerces 2.11.0" supported two version of XSD, but:

    2.1 If you will validate your document on XSD 1.0 mode, validator will say about incorrect document if "minVersion" not specified. If minVersion added, validator will skip checking for items from 1.1 version.

    2.2 If you will validate your document on XSD 1.1 mode, "minVersion" is not required.

  • So, I want said that the problem is not in the IDEA: if you used another validators checks could pass. I recommend always checking XML on several validators and versions to be sure that your XML is real correctly.

    链接地址: http://www.djcxy.com/p/18744.html

    上一篇: 带数据表中的时区的JSF convertDateTime

    下一篇: Intellij IDEA:如何验证XML SCHEMA 1