Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3976018
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:45:17+00:00 2026-05-20T04:45:17+00:00

I trying to use <xs:unique> and <xs:key>/<xs:keyref> with element values but I just can’t

  • 0

I trying to use <xs:unique> and <xs:key>/<xs:keyref> with element values but I just can’t get it to work. If I do it with attrubute values it works like a charm.

Test.xml

<test:config xmlns:test="http://www.example.org/Test"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.example.org/Test Test.xsd ">

    <test:location id="id1" path="/path2">
        <test:roles>
            <test:role>role1</test:role>
            <test:role>role2</test:role>
            <test:role>role2</test:role> <!-- DUPLICATE: FAIL VALIDATION  -->
        </test:roles>
        <test:action name="action1">
            <test:roles>
                <test:role>role1</test:role>
                <test:role>role1</test:role> <!-- DUPLICATE: FAIL VALIDATION -->
                <test:role>role3</test:role> <!-- NOT DEFINED: FAIL VALIDATION -->
            </test:roles>
        </test:action>
    </test:location>

</test:config>

I want ensure that roles are only defined once and that the roles defined under the action element are only those defined at the upper level.

Test.xsd

<xs:element name="config">
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="test:location" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>       
</xs:element>

<xs:element name="location" type="test:LocationType">
    <xs:key name="keyRole">
        <xs:selector xpath="test:roles" />
        <xs:field xpath="test:role" />
    </xs:key>
    <xs:keyref name="keyrefRole" refer="test:keyRole">
        <xs:selector xpath="test:action/test:roles" />
        <xs:field xpath="test:role" />
    </xs:keyref>
</xs:element>

<xs:complexType name="LocationType">
    <xs:sequence>
        <xs:element ref="test:roles" minOccurs="0" />
        <xs:element name="action" type="test:ActionType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string" use="required"/>
    <xs:attribute name="path" type="xs:string" use="required"/>
</xs:complexType>

<xs:element name="roles" type="test:RolesType">
    <xs:unique name="uniqueRole">
        <xs:selector xpath="." />
        <xs:field xpath="test:role" />
    </xs:unique>
</xs:element>

<xs:complexType name="RolesType">
    <xs:sequence>
        <xs:element name="role" type="xs:string" maxOccurs="unbounded"/>
    </xs:sequence>      
</xs:complexType>

<xs:complexType name="ActionType">
    <xs:sequence>
        <xs:element ref="test:roles" />
    </xs:sequence>
    <xs:attribute name="name" type="xs:string" use="required" />
</xs:complexType>

The validation fails with these messages:

Description Resource    Path    Location    Type
cvc-identity-constraint.3: Field "./test:role" of identity constraint "keyrefRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 15 XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "keyrefRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 16 XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "keyRole" matches more than one value within the scope of its selector; fields must match unique values.  Test.xml    /filebrowser-ejb/src/test/resources line 9  XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "keyRole" matches more than one value within the scope of its selector; fields must match unique values.  Test.xml    /filebrowser-ejb/src/test/resources line 10 XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "uniqueRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 9  XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "uniqueRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 10 XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "uniqueRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 15 XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "uniqueRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 16 XML Problem
cvc-identity-constraint.4.1: Duplicate unique value [role1] declared for identity constraint "uniqueRole" of element "roles".   Test.xml    /filebrowser-ejb/src/test/resources line 9  XML Problem
cvc-identity-constraint.4.1: Duplicate unique value [role1] declared for identity constraint "uniqueRole" of element "roles".   Test.xml    /filebrowser-ejb/src/test/resources line 15 XML Problem
cvc-identity-constraint.4.2.2: Duplicate key value [role1] declared for identity constraint "keyRole" of element "location".    Test.xml    /filebrowser-ejb/src/test/resources line 9  XML Problem
cvc-identity-constraint.4.3: Key 'keyrefRole' with value 'role3' not found for identity constraint of element 'location'.   Test.xml    /filebrowser-ejb/src/test/resources line 19 XML Problem

If I comment out the lines that should fail, validation still fails now with these messages:

Description Resource    Path    Location    Type
cvc-identity-constraint.3: Field "./test:role" of identity constraint "keyRole" matches more than one value within the scope of its selector; fields must match unique values.  Test.xml    /filebrowser-ejb/src/test/resources line 10 XML Problem
cvc-identity-constraint.3: Field "./test:role" of identity constraint "uniqueRole" matches more than one value within the scope of its selector; fields must match unique values.   Test.xml    /filebrowser-ejb/src/test/resources line 10 XML Problem

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:45:17+00:00Added an answer on May 20, 2026 at 4:45 am

    The field needs to identify a single item within the selector. You need something more like:

        <xs:selector xpath="test:roles/test:role" />
        <xs:field xpath="." />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use Double Hashing to hash a String key into a
I've been trying to use an index in my query but to no avail.
I'm trying to use ActiveRecord's find_or_create_by_*column* , but I'm getting errors from Postgres letting
I am trying to create a unique CD-KEY to put in our product's box,
I am trying to use a HashMap to map a unique string to a
I have been trying to use array_unique to remove duplicates from the search results
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables
I was trying use a set of filter functions to run the appropriate routine,
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.