【问题标题】:XML Schema unique constraint not recognised in IntelliJIntelliJ 中无法识别 XML Schema 唯一约束
【发布时间】:2018-03-01 05:03:39
【问题描述】:

在尝试了很多事情以在 IntelliJ 中因唯一约束而出错后,我开始怀疑 IntelliJ 是否甚至可以识别它。

我尝试的最后一个架构来自这篇帖子Unique constraint in XML Schema

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.brabantia.com/XMLSchema/ESBConfig"
        xmlns:tns="http://www.brabantia.com/XMLSchema/ESBConfig"
        elementFormDefault="qualified">
    <element name="authors">
        <complexType>
            <sequence>
                <element name="author" maxOccurs="unbounded" type="string"/>
            </sequence>
        </complexType>
        <unique name="uniqueAuthor">
            <selector xpath="author"/>
            <field xpath="."/>
        </unique>
    </element>
</schema>

我用来通过 IntelliJ 生成 XML。

<?xml version="1.0" encoding="UTF-8"?>
<esb:authors xmlns:esb="http://www.brabantia.com/XMLSchema/ESBConfig">
  <!--1 or more repetitions:-->
  <esb:author>string</esb:author>
  <esb:author>string</esb:author>
  <esb:author>string</esb:author>
</esb:authors>

应该显示错误,但没有。

Generate Instance Document From Schema 向导中,我检查了Enable restriction checkEnable unique check

所有其他检查都有效,例如枚举和模式。

有人可以告诉我这是架构中的内容还是 IntellJ 根本不支持的内容?

【问题讨论】:

  • 在您的架构中添加 xmlns:esb="http://www.brabantia.com/XMLSchema/ESBConfig" 并更改为 &lt;selector xpath="esb:author"/&gt;

标签: intellij-idea xsd xsd-validation


【解决方案1】:

添加xmlns:esb="http://www.brabantia.com/XMLSchema/ESBConfig"并更改为&lt;selector xpath="esb:author"/&gt; in your schema

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.brabantia.com/XMLSchema/ESBConfig"
        xmlns:esb="http://www.brabantia.com/XMLSchema/ESBConfig"
        elementFormDefault="qualified">
    <element name="authors">
        <complexType>
            <sequence>
                <element name="author" maxOccurs="unbounded" type="string"/>
            </sequence>
        </complexType>
        <unique name="uniqueAuthor">
            <selector xpath="esb:author"/>
            <field xpath="."/>
        </unique>
    </element>
</schema>

结果:

【讨论】:

    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2016-02-09
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    相关资源
    最近更新 更多