1
我的xs:unique不起作用。我嘗試了這個網站提供的各種解決方案。他們似乎都沒有爲我工作。我正在使用C#根據模式驗證我的xml。例如重複鍵密碼。問題與xml xs:獨特
下面是我的模式。
<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>