首页 文章

Intellij IDEA:如何验证XML SCHEMA 1

提问于
浏览
4

我正在使用JDK 7在IDEA 13.02中尝试XML SCHEMA 1.1

这是我从教程中获得的XML模式代码 . 当我在IntelliJ IDEA中打开此文件并单击“验证”时,出现以下错误:

cvc-complex-type.2.4.a:从元素'openContent'开始发现无效内容 . 其中一个'{“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}'是预期的 .

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>

有没有办法验证这个或升级IDEA使用的验证器?

2 回答

  • 0

    尝试将 xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"vc:minVersion="1.1" 添加到 <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>
    

    它将告知IDEA您正在使用XSD 1.1架构 .

    我已经将XSD 1.1与WebStorm 8一起使用,我相信它使用与IDEA相同的解析器 .

  • 0

    如果您的XML验证器支持XSD 1.0和1.1(不仅仅是一个版本),但无法自动识别XSD版本,则需要添加属性(如所述@helderdarocha)

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

    “schema”标签和验证器将知道需要用于检查的版本 .

    But if your XML-validator supports only XSD 1.0, you should remove unsupported items ,这是唯一的验证方式,对minVersion的引用将无法正常工作 .

    例如:

    • XML Validator“.Net 4.0(XSD 1.0)”将说明无效文档,无论您是否指定了最低版本;

    • XML Validator“Xerces 2.11.0”支持两个版本的XSD,但是:

    2.1如果您将在XSD 1.0模式下验证您的文档,如果未指定“minVersion”,验证者将说明不正确的文档 . 如果添加了minVersion,验证器将跳过检查1.1版本的项目 .

    2.2如果要在XSD 1.1模式下验证文档,则不需要“minVersion” .

    所以,我想说问题不在IDEA中:如果你使用了另一个验证器检查可以通过 . 我建议始终在几个验证器和版本上检查XML,以确保您的XML是真实的 .

相关问题