xml - Intellij IDEA : How to validate XML SCHEMA 1

标签 xml intellij-idea xsd xml-validation

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

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

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.

这是使用 XML Schema 1.1 增强功能的 XSD 文件:

<?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 使用的验证器?

最佳答案

尝试添加 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 Schema。

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

关于xml - Intellij IDEA : How to validate XML SCHEMA 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22255480/

相关文章:

android - 带动画图标的 FloatingActionButton

c# - 从 C# 调用 web 服务并发送未转义的 xml

xml - 为 XML 生成日期时间格式

android - 将多模块 Android Intellij 项目移植到 Android Studio

java - Java 中误导性的 XSD 验证错误

java - 在 Java 中过滤 xml 数据的更好方法

java - intellij Project make 和 Maven Compile 之间的区别?

java - 升级 IntelliJ 后 Play Framework 中的 Controller 出现 InstantiationException

xml - <xsd :all> and <xsd:sequence> in schema definition? 之间的区别

.net - XmlDocument.Validate 不检查无效的命名空间