XML模式唯一键
无可否认,我对模式是新手,我正试图让一个特定的属性在一个集合中是唯一的。我还需要将该值作为键,因为它将在其他地方引用 这是我当前的模式:XML模式唯一键,xml,schema,unique,Xml,Schema,Unique,无可否认,我对模式是新手,我正试图让一个特定的属性在一个集合中是唯一的。我还需要将该值作为键,因为它将在其他地方引用 这是我当前的模式: <xs:element name="subroutines" type="guisubroutines_Type" minOccurs="1"> <xs:key name="Subroutine_Key"> <xs:selector xpath="subroutine"/> <xs:
<xs:element name="subroutines" type="guisubroutines_Type" minOccurs="1">
<xs:key name="Subroutine_Key">
<xs:selector xpath="subroutine"/>
<xs:field xpath="@name"/>
</xs:key>
<xs:unique name="Subroutine_Unique">
<xs:selector xpath="subroutine"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:element>
<xs:complexType name="guisubroutines_Type" >
<xs:sequence>
<xs:element name="subroutine" type="subroutine_Type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="subroutine_Type">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
这是我的xml:
<subroutines>
<subroutine name="one"></subroutine>
<subroutine name="one"></subroutine>
</subroutines>
我目前正在使用VisualStudio2010,它说这个xml是有效的,但如果名称不存在,它会发出警告。如果两个名字是一样的,我希望它发出警告
有人能给我指一下正确的方向吗
谢谢您的时间。所以我在看了这里之后就明白了: 快速的答案是您需要将名称空间添加到xpath表达式中。 不确定这是VS事件还是一般情况,但是
<xs:key name="Subroutine_Key">
<xs:selector xpath="mstns:subroutine"/>
<xs:field xpath="@name"/>
</xs:key>
修复了我遇到的问题
再次感谢您的时间,我为浪费时间道歉