Xml XSD中的动态枚举

Xml XSD中的动态枚举,xml,xsd,Xml,Xsd,我有这样的xml结构: <main> <objects> <object name="book" /> <object name="table" /> </objects> <actions> <action input="book" /> <action input="table" /> <action input="book" />

我有这样的xml结构:

<main>
  <objects>
    <object name="book" />
    <object name="table" />
  </objects>
  <actions>
    <action input="book" />
    <action input="table" />
    <action input="book" />
  </actions>
</main>

这是一个简化的例子

我想创建使此类xml无效的xsd模式:

<main>
  <objects>
    <object name="book" />
    <object name="table" />
  </objects>
  <actions>
    <action input="book" />
    <action input="table" />
    <action input="fruit" />
  </actions>
</main>

因为在对象列表中没有名为“水果”的对象项

我不能简单地创建
,因为对象名称总是不同的,我不知道所有的名称。它似乎是一个列表,列出了应该动态创建的操作名称的可能值

为IntelliSense支持动态创建枚举会很好(
无法提供它)


有可能吗?

从生成的XSD开始,然后调整它以引入所需的约束。Intellisense部分高度依赖于编辑器。即使推断“智能”智能感知的元数据在那里(通过key/keyref),我怀疑市场上的编辑会利用它。下面的XSD将验证您提供的XML并使其失败

<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="main">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="objects">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element maxOccurs="unbounded" name="object">
                                <xsd:complexType>
                                        <xsd:attribute name="name" type="xsd:string" use="required"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="actions">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element maxOccurs="unbounded" name="action">
                                <xsd:complexType>
                                        <xsd:attribute name="input" type="xsd:string" use="required"/>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:key name="Objects">
            <xsd:selector xpath="objects/object"/>
            <xsd:field xpath="@name"/>
        </xsd:key>
        <xsd:keyref name="ActionToObjects" refer="Objects">
            <xsd:selector xpath="actions/action"/>
            <xsd:field xpath="@input"/>
        </xsd:keyref>
    </xsd:element>
</xsd:schema>

图表:


当它们是属性时,不要相信您可以,除非每次都更改xsd。若输入是一个元素,那个么可以使用ID和IDRef来实现xml的“外键”。e、 g将book和table放在一个元素中,则action具有一个必须引用现有id的idref属性