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

  • Home
  • SEARCH
  • 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 9211829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:23:09+00:00 2026-06-18T01:23:09+00:00

Hey I would like to force an attribute to be unique in my XML

  • 0

Hey I would like to force an attribute to be unique in my XML document. I am just beginning XML. I would like to make each person have a unique id. I have looked at xs:unique but can’t quite figure out where it goes here it won’t parse every time I try.
The Schema is as follows:

<?xml version='1.0' encoding='utf-8'?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
    <xs:element name='people' type='peopleType' /><!-- Root Element -->

    <xs:complexType name='peopleType'>
        <xs:sequence>
            <xs:element name='person' type='personType' maxOccurs='unbounded'/>
        </xs:sequence>
    </xs:complexType><!-- End peopleType-->

    <xs:complexType name='personType'>

        <xs:sequence>
            <xs:element name='name' type='nameType' maxOccurs='unbounded' />
            <xs:element name='email' minOccurs='1'>
                <xs:simpleType>
                    <xs:restriction base='xs:string'>
                        <xs:pattern value='([a-zA-Z0-9_-])*([.])?([a-zA-Z0-9_-])*([.])?([a-zA-Z0-9_-])*[@]([a-zA-Z0-9_-])*([.])?([a-zA-Z0-9_-])*([.])?([a-zA-Z0-9_-])*' />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name='favColour' type='colourType' minOccurs='0' />

        </xs:sequence>

        <xs:attribute name='id' type='xs:integer' />

    </xs:complexType><!--End personType -->

    <xs:complexType name='nameType'>
        <xs:sequence>
            <xs:element name='given' minOccurs='1'>
                <xs:simpleType>
                    <xs:restriction base='xs:string'>
                        <xs:pattern value='[A-Z]([a-z])*' />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name='family' minOccurs='1'>
                <xs:simpleType>
                    <xs:restriction base='xs:string'>
                        <xs:pattern value='[A-Z]([a-z])*' />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType><!-- End nameType -->

    <xs:complexType name='colourType'>
        <xs:sequence>
            <xs:element name='red' minOccurs='1' >
                <xs:simpleType>
                    <xs:restriction base='xs:integer'>
                        <xs:minInclusive value='0' />
                        <xs:maxInclusive value='255' />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name='green' minOccurs='1' >
                <xs:simpleType>
                    <xs:restriction base='xs:integer'>
                        <xs:minInclusive value='0' />
                        <xs:maxInclusive value='255' />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name='blue' minOccurs='1'>
                <xs:simpleType>
                    <xs:restriction base='xs:integer'>
                        <xs:minInclusive value='0' />
                        <xs:maxInclusive value='255' />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType><!-- End colourType -->
</xs:schema>

[EDIT] After taking advice I made the following changes. It parses okay but doesn’t enforce the unique attributes.

<xs:complexType name='peopleType'>
        <xs:sequence>
            <xs:element name='person'  type='personType' maxOccurs='unbounded'>
                <xs:unique name="MyUserNameUniqueKey">
            <xs:selector xpath="person" />
            <xs:field xpath="@id" />
            </xs:unique>
            </xs:element>
        </xs:sequence>
    </xs:complexType><!-- End peopleType--> 
  • 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-06-18T01:23:11+00:00Added an answer on June 18, 2026 at 1:23 am

    In the element declaration for people, add an xs:unique declaration with selector xpath=”person”, field xpath=”@id”. If it doesn’t work, show us what you tried.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I have an XML file and I would like to navigate to a
Hey. I have an XML file and would like to use PHP to display
Hey guys, I have developed a small site that i would like to embed
Hey guys this should be simple, I'm just not seeing it, I would like
Let's say I have the string Hey . I would like to determine all
Hey everyone. I would like to create a joomla menu but have it display
Hey guys, I have some questions would like to ask: I wanna ask how
Hey! I have a xib file were i would like a round rect button
Hey i would like do have your input on this I use this to
Hey I have made an WCF service and would like to be able to

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.