我有这样的XML:
<extras>
<display type="simple_2_lines" address="42"/>
<temperature name="asd" address="42"/>
<humidity name="h1" address="42"/>
</extras>
我想设置地址属性的唯一属性,如下所示:
<xs:element name="extras">
<xs:complexType>
<xs:sequence>
<xs:element ref="display" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="temperature" minOccurs="0" maxOccurs="unbounded" />
<xs:element ref="humidity" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:unique name="unique_address">
<xs:selector xpath="display | temperature | humidity"/>
<xs:field xpath="@address"/>
</xs:unique>
</xs:element>
如果所有节点都具有相同的地址属性,它可以很好地工作,但如果我设置了它,它就无法检测到多个地址:
<extras>
<display type="simple_2_lines" address="42"/>
<temperature name="asd" address="43"/>
<humidity name="h1" address="42"/>
</extras>
如何撰写正确的规则?