我的 xs:unique 不工作。我尝试了本网站提供的各种解决方案。它们似乎都不适合我。我正在使用 C# 针对架构验证我的 xml。例如,重复密钥 passwordomni。
下面是我的架构。
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mstns="http://tempuri.org/SqlManifest.xsd">
<xs:element name="sqlmanifest">
<xs:complexType>
<xs:sequence>
<xs:element name="sqlparameters" maxOccurs="1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="sqlparameter" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="key" use="required"/>
<xs:attribute type="xs:string" name="description" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:unique name="unique-key">
<xs:selector xpath ="mstns:sqlparameter"/>
<xs:field xpath="@key"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="sqlcommands" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="sqlcommand" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="path" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:unique name="unique-path">
<xs:selector xpath ="mstns:sqlcommand"/>
<xs:field xpath="@path"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:boolean" name="transactional"/>
</xs:complexType>
</xs:element>
</xs:schema>
下面是我的xml
<sqlmanifest transactional="false">
<sqlparameters>
<sqlparameter key="dbpath" description="Please enter dbpath"/>
<sqlparameter key="passworduserOmni" description="Please enter password for OmniUser"/>
<sqlparameter key="passwordadminOmni" description="Please enter password for OmniAdminUser"/>
<sqlparameter key="passwordadminOmni" description="Please enter password for OmniAdminUser"/>
</sqlparameters>
<sqlcommands>
<sqlcommand path="scripts/script1.sql"/>
<sqlcommand path="scripts/script2.sql" />
<sqlcommand path="scripts/scripts3.sql" />
<sqlcommand path="scripts/scripts4.sql" />
<sqlcommand path="scripts/script1.sql"/>
</sqlcommands>
</sqlmanifest>