Using "unique" with "field xpath=" value being variable instead of fixed

Hi,

I have a case where my "unique" identifier field name (in an xsd) can take on different values (based on another value in the xml).

My case is validating people--which can either be identified by a Social Security Number or a UniqueId. I’d like the xsd to validate based on the SSN or UniqueId specified in the xml.

HERE'S THE "FIXED" CASE (which works fine for validating against a fixed field name – SSN in this case):

For a "fixed" case (where only SSN is the unique value):

[xsd fragment]

<xs:unique name="ProfileUnique">

<xs:selector xpath="Profiles/Profile"/>

<xs:field xpath="Ssn"/>

</xs:unique>

[xml]

< xml version="1.0" encoding="UTF-8" >

<Domains>

<Domain>

<DomainName>B</DomainName>

<Profiles>

<Profile>

<Ssn>655555556</Ssn>

<LastName>BDoe</LastName>

<FirstName>BJane</FirstName>

<MiddleInitial>C</MiddleInitial>

<DateOfBirth>1945-05-09</DateOfBirth>

<CustomId>111</CustomId>

</Profile>

<Profile>

<Ssn>655555556</Ssn>

<LastName>BDoe</LastName>

<FirstName>BJane</FirstName>

<MiddleInitial>C</MiddleInitial>

<DateOfBirth>1945-05-09</DateOfBirth>

<CustomId>111</CustomId>

</Profile>

</Profiles>

</Domain>

</Domains>

HERE'S THE VARIABLE CASE (which I'm trying to figure out how to accomplish):

For a "variable" case (where only SSN –or- CUSTOMID is the unique value):

[xsd fragment]

<xs:simpleType name="UniqueProfileIdentifierType">

<xs:restriction base="xs:string">

<xs:enumeration value="NotSet"/>

<xs:enumeration value="None"/>

<xs:enumeration value="Ssn"/>

<xs:enumeration value="CustomId"/>

</xs:restriction>

</xs:simpleType>

<xs:unique name="ProfileUnique">

<xs:selector xpath="Profiles/Profile"/>

<xs:field xpath= ****< UniqueProfileIdentifierType >****/>

</xs:unique>

[xml]

< xml version="1.0" encoding="UTF-8" >

<Domains>

<Domain>

<DomainName>B</DomainName>

<UniqueProfileIdentifier>Ssn</UniqueProfileIdentifier>

<Profiles>

<Profile>

<Ssn>655555556</Ssn>

<LastName>BDoe</LastName>

<FirstName>BJane</FirstName>

<MiddleInitial>C</MiddleInitial>

<DateOfBirth>1945-05-09</DateOfBirth>

<CustomId>111</CustomId>

</Profile>

<Profile>

<Ssn>655555556</Ssn>

<LastName>BDoe</LastName>

<FirstName>BJane</FirstName>

<MiddleInitial>C</MiddleInitial>

<DateOfBirth>1945-05-09</DateOfBirth>

<CustomId>111</CustomId>

</Profile>

</Profiles>

</Domain>

</Domains>

Does someone know how to do this where "field xpath" can be variable (e.g. SocialSecurityNumber OR CustomId--for my case)

Thanks!

Andy



Answer this question

Using "unique" with "field xpath=" value being variable instead of fixed

  • Michael Bird

    GreenStone90 wrote:

    <xs:simpleType name="UniqueProfileIdentifierType">

    <xs:restriction base="xs:string">

    <xs:enumeration value="NotSet"/>

    <xs:enumeration value="None"/>

    <xs:enumeration value="Ssn"/>

    <xs:enumeration value="CustomId"/>

    </xs:restriction>

    </xs:simpleType>

    <xs:unique name="ProfileUnique">

    <xs:selector xpath="Profiles/Profile"/>

    <xs:field xpath= ****< UniqueProfileIdentifierType >****/>

    </xs:unique>

    <UniqueProfileIdentifier>Ssn</UniqueProfileIdentifier>

    <Profiles>

    <Profile>

    <Ssn>655555556</Ssn>

    <LastName>BDoe</LastName>

    <FirstName>BJane</FirstName>

    <MiddleInitial>C</MiddleInitial>

    <DateOfBirth>1945-05-09</DateOfBirth>

    <CustomId>111</CustomId>

    </Profile>

    What you want there is simply not possible that way. In the schema you need to write an XPath expression selecting elements or attributes defined in the schema. Your simple type definition does not define any elements or attributes, it enumerates some strings you seem to want to be interpreted as element names. But the schema language respectively schema validation does not work that way.



  • Khurram01

    Let me see if I understand your problem. Do you want your schema to say that you can only have one or the other (but not both) and all occurances of Ssn should be unique and all occurances of CustomId should be unique If this is the case, the following schema should do what you want. If not, you'll need to clarify the problem a bit more.

    < xml version="1.0" encoding="utf-8" >

    <xs:schema attributeFormDefault="unqualified"

    elementFormDefault="qualified"

    targetNamespace="http://mytns"

    xmlns="http://mytns"

    xmlns:tns="http://mytns"

    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="Profiles">

    <xs:complexType>

    <xs:sequence>

    <xs:element maxOccurs="unbounded" name="Profile">

    <xs:complexType>

    <xs:sequence>

    <xs:choice>

    <xs:element name="Ssn" type="xs:unsignedInt" />

    <xs:element name="CustomId" type="xs:unsignedInt"/>

    </xs:choice>

    </xs:sequence>

    </xs:complexType>

    </xs:element>

    </xs:sequence>

    </xs:complexType>

    <xs:unique name="ProfileUniqueSsn">

    <xs:selector xpath="tns:Profile/tns:Ssn"/>

    <xs:field xpath="."/>

    </xs:unique>

    <xs:unique name="ProfileUniqueCustomID">

    <xs:selector xpath="tns:Profile/tns:CustomId"/>

    <xs:field xpath="."/>

    </xs:unique>

    </xs:element>

    </xs:schema>



  • Using "unique" with "field xpath=" value being variable instead of fixed