问题
I would like to pass uniqueness of each attribute in the list of passengers in XML file.
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>
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>
How can I modify the attribute "resnumb" to make reservation number unique?
Thanks,
回答1:
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>
来源:https://stackoverflow.com/questions/34693570/xsunique-how-to-implement-into-attribute