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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:30:30+00:00 2026-06-05T23:30:30+00:00

How can i validate the text length of the element that has an attribute.

  • 0

How can i validate the text length of the element that has an attribute.
E.g:

    <sport code="FB">Football</sport>

Now i need to restrict the possible values of the code attribute(like “FB”, “BB”, “TT”)
and also i need to restrict the possible values and length of the text(“Football”, “BasketBall”, “TableTennis”) and also the maximum length of these text(“Football”, “BasketBall”, “TableTennis”) can be 20.

I tried with

<complexType name="sport">
  <simpleContent>
    <extension base="string">
        <attribute name="code" type="code" />
    </extension>
  </simpleContent>
</complexType>
<simpleType name="code">
    <restriction base="string">
        <enumeration value="FB" />
        <enumeration value="BB" />
        <enumeration value="TT" />
    </restriction>
</simpleType>

But i cant validate the length of the text “Foolball” (also the possible values)
Can you please help about how to validate both the code and the text.
Thanks

  • 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-05T23:30:34+00:00Added an answer on June 5, 2026 at 11:30 pm

    I had this identical question, and was hopeful when I saw there was an accepted answer. However, that answer is exactly what I tried, but I was getting a schema invalid error. Apparently, you can’t restrict simpleContent within a complexType, only extend it. Additionally, you can’t have both an attribute and simpleContent within a complexType. Searching for examples in books around the office, I came up with a fix, which I adapted to this question in case someone else has this problem in the future:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                xmlns:sp="http://www.ckhrysze.net/sports/1.0"
                targetNamespace="http://www.ckhrysze.net/sports/1.0"
            >
    
      <xsd:element name="sports">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="sport" type="sp:sportType" minOccurs="1" maxOccurs="unbounded" />
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    
      <xsd:complexType name="sportType">
        <xsd:simpleContent>
          <xsd:extension base="sp:sportEnumeration">
            <xsd:attribute name="code" type="sp:codeEnumeration" />
          </xsd:extension>
        </xsd:simpleContent>
      </xsd:complexType>
    
      <xsd:simpleType name="sportEnumeration">
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="Football" />
          <xsd:enumeration value="Basketball" />
        </xsd:restriction>
      </xsd:simpleType>
    
      <xsd:simpleType name="codeEnumeration">
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="FB" />
          <xsd:enumeration value="BB" />
        </xsd:restriction>
      </xsd:simpleType>
    
    </xsd:schema>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I validate an XML file against a DTD that is stored locally
I am using RegexKitLite, i want to validate that my uitextfield has + prefixed
i need to validate a textfield input that allows two digits after a .
I have a form that I validate it using the JavaScript. Now when I
I want to validate my text are while entering data. I had written code
i have to validate on length of text . so, on Editing Did End
I need to validate a text based upon a regular expression in javascript. My
I want to write a function which can validate a given value (passed as
I am looking for a Java framework which can validate order of elements in
I have vote and votedown tables for posts. I can validate uniqueness within the

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.