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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:03:25+00:00 2026-05-22T01:03:25+00:00

here is my xml document <root> <num>3</num> <a> <b> <c n=m></c> <c></c> <c n=e></c>

  • 0

here is my xml document

<root>
 <num>3</num>
 <a>
  <b>
   <c n="m"></c>
   <c></c>
   <c n="e"></c>
  </b>
  <b>
   <c n="s"></c>
   <c n="w"></c>
   <c></c>
  </b>
  <b>
   <c n="q"></c>
   <c></c>
   <c n="u"></c>
  </b>
 </a>
</root>

I want to created a xml Schema.
Element c in b must occurs only n time.(n is in num element)
I think it use key, keyref or unique.

  • 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-22T01:03:26+00:00Added an answer on May 22, 2026 at 1:03 am

    It is not possible.

    Key, keyref and unique will not help. Unique will ensure that you have no duplicate items. And key and keyref will ensure that the elements in place B match those in place A.

    The maxOccurs restriction requires a simple integer argument. It is not possible to calculate the integer by any kind of Xpath expression. See here: http://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints

    Update

    If you want to solve your problem with unique, key and key ref you have to create an number index in an attribute. The following image illustrates the schema:

    enter image description here

    You have to add an attribute to your c nodes which references a master attribute index. In this example it is stored in multiple num elements. You can put an integer restriction, a unique and a key constrain on /root/num@count. After that you create a reference constrain from /root/a/b/c@count to /root/num@count. This will create a max constrain. You can have as many c nodes as num nodes but you can have less, too.

    This is the schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xs:element name="root">
        <xs:annotation>
          <xs:documentation>Comment describing your root element</xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="num" maxOccurs="unbounded">
              <xs:complexType>
                <xs:attribute name="count" type="xs:unsignedInt" use="required"/>
              </xs:complexType>
            </xs:element>
            <xs:element name="a" maxOccurs="unbounded">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="b" maxOccurs="unbounded">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="c" maxOccurs="unbounded">
                          <xs:complexType>
                            <xs:attribute name="count" type="xs:integer" use="required"/>
                          </xs:complexType>
                        </xs:element>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
        <xs:unique name="num_unique">
          <xs:selector xpath="num"/>
          <xs:field xpath="@count"/>
        </xs:unique>
        <xs:key name="num_key">
          <xs:selector xpath="num"/>
          <xs:field xpath="@count"/>
        </xs:key>
        <xs:keyref name="num_ref" refer="num_key">
          <xs:selector xpath="a/b/c"/>
          <xs:field xpath="@count"/>
        </xs:keyref>
      </xs:element>
    </xs:schema>
    

    And this would be a valid file:

    <?xml version="1.0" encoding="UTF-8"?>
    <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="root.xsd">
      <num count="1"/>
      <num count="2"/>
      <num count="3"/>
      <a>
        <b>
          <c count="1"/>
        </b>
        <b>
          <c count="1"/>
          <c count="2"/>
        </b>
      </a>
    </root>
    

    It will become invalid if you add a <c count="4"/>. Right now I have no idea how to make it an identity reference. Maybe it is possible to reverse the reference direction…

    But never the less it is no good idea to place a constrain into the same file as the data itself. If you do not trust your data source it does not make much sense to ask your data source for a self given constrain. You must put the constrain into the schema or extend the validation by some kind of program logic. For example you can count the number of all c nodes in their parent and check if they are all the same or are all equal to a given number. That would make much more sense, because that is the only secure way to enforce the constrain.

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

Sidebar

Related Questions

Here's the deal. I have an XML document with a lot of records. Something
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
In my environment here I use Java to serialize the result set to XML.
Here is my XML document: <?xml version="1.0" encoding="UTF-8"?> <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> <rootfiles> <rootfile full-path="content.opf"
I have an XML document with a default namespace indicated at the root. Something
Suppose I have this XML document... <root> <str name=My node's attribute>My string's value</str> </root>
Let's say we have the following XML document: <root> <options> ... </options> <children> <child
I have the following code. from xml.dom.minidom import Document doc = Document() root =
As in, if I have an XML Document <root a=value> <item name=first> x <foo
I have an XML document, want to do syntax highlighting. The code uses XPathDocument

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.