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 8295885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:45:53+00:00 2026-06-08T14:45:53+00:00

I have following xml and xsd as basic example for my question: XML <parentgroup>

  • 0

I have following xml and xsd as basic example for my question:

XML

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="3" />
      <childgroup id="4">
        <child id="5" />
        <child id="2" />
      </childgroup>
      <child id="5" />
    </parent>


    <parent id="2">
      <childgroup id="33">
        <child id="1" />
        <child id="4" />
      </childgroup>
      <child id="1" />
      <child id="5" />
      <childgroup id="4">
        <child id="1" />
        <child id="6" />
      </childgroup>
    </parent>

  </parentgroup>

XSD

<xsd:element name="parentgroup" type="parentgroup">
    <xsd:unique name="UniqueParentId">
      <xsd:selector xpath="child::parent"></xsd:selector>
      <xsd:field xpath="@id"></xsd:field>
    </xsd:unique>
  </xsd:element>

  <xsd:complexType name="parentgroup">
    <xsd:sequence maxOccurs="unbounded">
      <xsd:element name="parent" type="parent" maxOccurs="unbounded" minOccurs="1">

        <xsd:unique name="UniqueChildId">
          <xsd:selector xpath=".//*"></xsd:selector>
          <xsd:field xpath="@id"></xsd:field>
        </xsd:unique>

      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:int" />
  </xsd:complexType>

  <xsd:complexType name="parent">
    <xsd:choice maxOccurs="unbounded" minOccurs="1">
      <xsd:element name="child" type="child" maxOccurs="unbounded" minOccurs="1"></xsd:element>
      <xsd:element name="childgroup" type="childgroup" maxOccurs="unbounded" minOccurs="1"></xsd:element>

    </xsd:choice>

    <xsd:attribute name="id" type="xsd:int" />
  </xsd:complexType>

  <xsd:complexType name="childgroup">
    <xsd:sequence maxOccurs="unbounded">
      <xsd:element name="child" type="child" maxOccurs="unbounded" minOccurs="1"></xsd:element>

    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:int" />
  </xsd:complexType>

  <xsd:complexType name="child">
    <xsd:attribute name="id" type="xsd:int" />
  </xsd:complexType>

Task

  1. All parents have an unique “id” attr. and no child has the same “id” attr. like his parent.
  2. Childs and Childgroups in a parent have unique “id” attr. excluding the Childs in the Childgroup. (ids are unique in the first depth plus parent)
  3. Childs in a Childgroup have unique “id” attr. (so it is allowed that the ids of childs in a childgroup are equal to ids of childs out of the childgroup in the same parent, but its not allowed that it is euqal to id of own childgroup, like 2. point [(ids are unique in the first depth plus parent)] )

1. Question

The points 1. and 2. are clear, but I dont know how to exclude the descendant of childgroup, i tried following but get always xpath syntax error

First Try

     <xsd:element name="parent" type="parent" maxOccurs="unbounded" minOccurs="1">

        <xsd:unique name="UniqueChildId">
          <xsd:selector xpath=".//*[not(childgroup)]"></xsd:selector>
          <xsd:field xpath="@id"></xsd:field>
        </xsd:unique>

      </xsd:element>

Second Try

     <xsd:element name="parent" type="parent" maxOccurs="unbounded" minOccurs="1">

        <xsd:unique name="UniqueChildId">
          <xsd:selector xpath=".//*[not(child::childgroup)]"></xsd:selector>
          <xsd:field xpath="@id"></xsd:field>
        </xsd:unique>

      </xsd:element>

Third Try

     <xsd:element name="parent" type="parent" maxOccurs="unbounded" minOccurs="1">

        <xsd:unique name="UniqueChildId">
          <xsd:selector xpath="child::*[not(childgroup)]"></xsd:selector>
          <xsd:field xpath="@id"></xsd:field>
        </xsd:unique>

      </xsd:element>

Thanks for your help!

Invalid Xml

E.g.1

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="3" />
      <childgroup id="7">
        <child id="5" />
        <child id="6" />
      </childgroup>
      <child id="7" />
    </parent>


    <parent id="8">
      <childgroup id=9">
        <child id="10" />
        <child id="9" />
      </childgroup>
      <child id="12" />
      <child id="13" />
      <childgroup id="14">
        <child id="15" />
        <child id="16" />
      </childgroup>
    </parent>

  </parentgroup>

Reason

  1. Invalid because in first parent: childgroup id=”7″ has same id as child id=”7″
  2. Invalid because in second parent: child id=”9″ has same id as his “father” childgroup id=”9″

E.g.2

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="3" />
      <childgroup id="4">
        <child id="5" />
        <child id="7" />
      </childgroup>
      <child id="7" />
    </parent>


    <parent id="8">
      <childgroup id=9">
        <child id="10" />
        <child id="8" />
      </childgroup>
      <child id="12" />
      <child id="14" />
      <childgroup id="14">
        <child id="15" />
        <child id="16" />
      </childgroup>
    </parent>

  </parentgroup>

Reason

  1. Invalid because in second parent: childgroup id=”14″ has same id as child id=”14″

E.g.2

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="7" />
      <childgroup id="4">
        <child id="5" />
        <child id="6" />
      </childgroup>
      <child id="7" />
    </parent>


    <parent id="8">
      <childgroup id=9">
        <child id="10" />
        <child id="11" />
      </childgroup>
      <child id="12" />
      <child id="14" />
      <childgroup id="15">
        <child id="16" />
        <child id="11" />
      </childgroup>
    </parent>

  </parentgroup>

Reason

  1. Invalid because in first parent: child id=”7″ has same id as child id=”7″

E.g.2

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="3" />
      <childgroup id="4">
        <child id="1" />
        <child id="2" />
      </childgroup>
      <child id="7" />
    </parent>


    <parent id="8">
      <childgroup id=9">
        <child id="10" />
        <child id="11" />
      </childgroup>
      <child id="12" />
      <child id="14" />
      <childgroup id="9">
        <child id="16" />
        <child id="11" />
      </childgroup>
    </parent>

  </parentgroup>

Reason

  1. Invalid because in second parent: childgroup id=”9″ has same id as childgroup id=”9″

Valid Xml

E.g.1

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="3" />
      <childgroup id="4">
        <child id="5" />
        <child id="6" />
      </childgroup>
      <child id="7" />
    </parent>


    <parent id="8">
      <childgroup id=1">
        <child id="2" />
        <child id="3" />
      </childgroup>
      <child id="4" />
      <child id="5" />
      <childgroup id="6">
        <child id="7" />
        <child id="9" />
      </childgroup>
    </parent>

  </parentgroup>

E.g.2

  <parentgroup>

    <parent id="1">
      <child id="2" />
      <child id="3" />
      <childgroup id="4">
        <child id="5" />
        <child id="7" />
      </childgroup>
      <child id="7" />
    </parent>


    <parent id="8">
      <childgroup id=1">
        <child id="2" />
        <child id="5" />
      </childgroup>
      <child id="4" />
      <child id="5" />
      <childgroup id="6">
        <child id="2" />
        <child id="5" />
      </childgroup>
    </parent>

  </parentgroup>
  • 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-08T14:45:55+00:00Added an answer on June 8, 2026 at 2:45 pm

    I’ve cleaned up and corrected your errors. Below is the new XSD that works with the posted XML and the requirements the way I understood them. I hope the diagram below helps you visualize better the constraints and the XPath you should use.

    QTAssistant diagram showing XSD constraints

    The modified XSD:

    <?xml version="1.0" encoding="utf-8" ?>
    <!--XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com)-->
    <xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="parentgroup" type="parentgroup">
            <xsd:unique name="UniqueParentId">
                <xsd:selector xpath="parent"/>
                <xsd:field xpath="@id"/>
            </xsd:unique>
        </xsd:element>
    
        <xsd:complexType name="parentgroup">
            <xsd:sequence maxOccurs="unbounded">
                <xsd:element name="parent" type="parent" maxOccurs="unbounded">
                    <xsd:unique name="UniqueChildId">
                        <xsd:selector xpath=".|childgroup|child"/>
                        <xsd:field xpath="@id"/>
                    </xsd:unique>
                </xsd:element>
            </xsd:sequence>
            <xsd:attribute name="id" type="xsd:int"/>
        </xsd:complexType>
    
        <xsd:complexType name="parent">
            <xsd:choice maxOccurs="unbounded">
                <xsd:element name="child" type="child" maxOccurs="unbounded"/>
                <xsd:element name="childgroup" type="childgroup" maxOccurs="unbounded">
                    <xsd:unique name="UniqueChildIdInChildGroup">
                        <xsd:selector xpath=".|child"/>
                        <xsd:field xpath="@id"/>
                    </xsd:unique>
                </xsd:element>
            </xsd:choice>
            <xsd:attribute name="id" type="xsd:int"/>
        </xsd:complexType>
    
        <xsd:complexType name="childgroup">
            <xsd:sequence maxOccurs="unbounded">
                <xsd:element name="child" type="child" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attribute name="id" type="xsd:int"/>
        </xsd:complexType>
    
        <xsd:complexType name="child">
            <xsd:attribute name="id" type="xsd:int"/>
        </xsd:complexType>
    </xsd:schema>
    

    UPDATE: The XSD works fine with all sample XMLs. Here is what QTAssistant is saying about each:

    Invalid:
    E.g. 1:

    Error occurred while loading [], line 9 position 4
    There is a duplicate key sequence '7' for the 'UniqueChildId' key or unique identity constraint.
    Error occurred while loading [], line 15 position 5
    There is a duplicate key sequence '9' for the 'UniqueChildIdInChildGroup' key or unique identity constraint.
    ParentChildChildGroup-Inv-Eg1.xml is invalid.

    E.g. 2:

    Error occurred while loading [], line 21 position 5
    There is a duplicate key sequence '14' for the 'UniqueChildId' key or unique identity constraint.
    ParentChildChildGroup-Inv-Eg2.xml is invalid.

    E.g. 2 (3?):

    Error occurred while loading [], line 9 position 4
    There is a duplicate key sequence '7' for the 'UniqueChildId' key or unique identity constraint.
    ParentChildChildGroup-Inv-Eg3.xml is invalid.

    E.g. 2 (4?):

    Error occurred while loading [], line 21 position 5
    There is a duplicate key sequence '9' for the 'UniqueChildId' key or unique identity constraint.
    ParentChildChildGroup-Inv-Eg4.xml is invalid.

    What you described as valid XMLs are successfully validated.

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

Sidebar

Related Questions

I have the following XML: <ns:response xmlns:ns=http://example.com xmlns:ax=http://example.com/xsd > <ns:return type=mytype> <ax:roleID>1</ax:roleID> <ax:roleName>ADM</ax:roleName> </ns:return>
I have the following XML: <customer> <name>John Paul</name> <cpf_cnpj>1376736333334</cpf_cnpj> </customer> The <cpf_cnpj> element must
I have the following .xsd code: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema id=MyDataSet> <xs:element name=Row>
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I have the following xml schema: <?xml version=1.0 encoding=utf-8?> <xsd:schema xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:xsd=http://www.w3.org/2001/XMLSchema attributeFormDefault=unqualified
I have the following XML sequence <property name=a value=x /> <property name=b value=xx />
I have the following start of an XSD: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:no=http://www.sychophants.com>
I have the following xsd files: SchemaA <?xml version=1.0 encoding=utf-8?> <xs:schema targetNamespace=http://schemaA elementFormDefault=qualified xmlns=http://schemaA
I have the following xml: <?xml version=1.0 encoding=UTF-8?> <sections> <section name=Options> <item key=HLVersionControlWebServiceURL value=http://www.personec.no/webservices/HLVersionControl/HLVersionControl.asmx
I have the following piece of xml: <MyField> <FieldName>Blah</FieldName> <ValueFormatting xsi:type=DateFormatter> <Format>dd/MM/yy</Format> </ValueFormatting> </MyField>

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.