我正在使用 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/