2

I have such xml structure:

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

This is a simplified example.

I want to create xsd schema which invalidates such xml:

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

because of there is no object item with the name "fruit" into list of objects.

I can't simply create <xsd:enumeration> because object names are always different and I don't know all of them. It seems to be a list of possible values of action's names should be created dynamically.

It would be wonderful to create enumeration dynamically for IntelliSense support (<xsd:assert> can't provide it).

Is it possible?

4

1 に答える 1

3

生成された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図を示すQTAssistant

于 2012-07-28T16:15:22.033 に答える