xs:unique 如何实现成属性? [英] xs:unique how to implement into attribute?
本文介绍了xs:unique 如何实现成属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 XML 文件中传递乘客列表中每个属性的唯一性.
I would like to pass uniqueness of each attribute in the list of passengers in XML file.
我的 xml 文件如下所示:
My xml file look like this:
<passengers>
<passenger resnumb="872-AA">
<name>John</name>
<surname>Doe</surname>
<datebirth>1997-10-01</datebirth>
<pricetix>1321</pricetix>
<telephone>+48 128382812</telephone>
<dateofbuy>2015-10-01</dateofbuy>
<comment>Confirmed</comment>
</passenger>
<passenger resnumb="962-AA">
<name>Jack</name>
<surname>Lawnmower</surname>
<datebirth>1993-01-01</datebirth>
<pricetix>1243</pricetix>
<telephone>+48 183722842</telephone>
<dateofbuy>2015-09-01</dateofbuy>
<comment>Confirmed</comment>
</passenger>
</passengers>
XML 文件如下所示:
And XML file looks like this:
<xs:complexType name="passengerslist">
<xs:sequence>
<xs:element name="passenger" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="surname" type="xs:string"/>
<xs:element name="datebirth" type="xs:date"/>
<xs:element name="pricetix" type="xs:integer"/>
<xs:element name="telephone" type="xs:string"/>
<xs:element name="dateofbuy" type="xs:date" minOccurs="0"/><!--Punkt 3-->
<xs:element ref="comment" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="resnumb" type="PNR" use="required"/><!--Tutaj mamy punkt 4-->
</xs:complexType>
<xs:unique name="unique-resnumb">
<xs:selector xpath="passenger"/>
<xs:field xpath="@resnumb"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
我的代码还包含使用正则表达式模式创建的自定义类型:
Also my code contains a custom type created using a regular expression pattern:
<xs:simpleType name="PNR">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3}-[A-Z]{2}"/>
</xs:restriction>
</xs:simpleType>
如何修改resnumb"属性以使预订编号唯一?
How can I modify the attribute "resnumb" to make reservation number unique?
谢谢,
推荐答案
考虑发布最少但完整的示例.基本上将 xs:unique
移动到 xs:element
声明,例如
Consider to post minimal but complete samples. Basically move the xs:unique
to the xs:element
declaration e.g.
<xs:element name="passengers" type="passengerslist">
<xs:unique name="unique-resnumb">
<xs:selector xpath="passenger"/>
<xs:field xpath="@resnumb"/>
</xs:unique>
</xs:element>
这篇关于xs:unique 如何实现成属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文