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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:01:25+00:00 2026-06-09T19:01:25+00:00

My question is, if i have to validate if just one has an attribute

  • 0

My question is, if i have to validate if just one has an attribute true, and one of all have to be true, using the xml:

<addresses>
    <address>
        <primary>true</primary>
        <street>One str.</street>
        <number>111</number>
    </address>
    <address>
        <primary>false</primary>
        <street>Two str.</street>
        <number>222</number>
    </address>
</addresses>

How to do??

ps: Sorry about my english.

  • 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-09T19:01:26+00:00Added an answer on June 9, 2026 at 7:01 pm

    The simplest way to do this (or so it seems to me! others may disagree) is to use a slightly different XML structure. You want one primary address and zero or more non-primary addresses. Any XML validation method (DTDs, XSD, …) makes it easy to say that, if you use different names for the things that have different requirements. If the XML structure becomes

    <addresses>
      <primary-address>
        <street>One str.</street>
        <number>111</number>
      </primary-address>
      <address>
        <street>Two str.</street>
        <number>222</number>
      </address>
    </addresses>
    

    then it’s easy to write an XSD schema that constrains addresses to contain exactly one primary address, and that explicitly captures the fact that primary addresses and other addresses have the same structure:

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      elementFormDefault="qualified"> 
    
      <xsd:complexType name="address">
        <xsd:sequence>
          <xsd:element ref="street"/>
          <xsd:element ref="number"/>
        </xsd:sequence>
      </xsd:complexType>
    
      <xsd:element name="primary-address" type="address"/>  
      <xsd:element name="address" type="address"/>  
      <xsd:element name="addresses">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref="primary-address"/>
            <xsd:element ref="address" minOccurs="0" maxOccurs="unbounded"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    
      <xsd:complexType name="mixed" mixed="true">
        <xsd:sequence/>
      </xsd:complexType>
    
      <xsd:element name="street" type="mixed"/>
      <xsd:element name="number" type="mixed"/>
    </xsd:schema>
    

    If you cannot change your XML structure, or do not want to, you can switch to XSD 1.1 and use an assertion to enforce the constraint, or you can use Schematron to do so.

    Or (this is a slightly dirty trick), you can say (1) that the only legal value for the primary attribute is true, (2) that the attribute is optional on the address element, and (3) that each occurrence of the primary attribute must have a unique value.

    But I really recommend changing the XML structure.

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

Sidebar

Related Questions

Question Is it posible to have the Validation.Validate() method of the Validation Application Block
I have loop designed to validate the user input on a question, it was
this is a simple question. I have a form that is being validated using
I have a webform with two custom validators: One to validate that a string
I have a problem and a question with using Strings. The problem I am
Just like described in title of question - I would like to have default
I have a ASP.NET MVC 2.0 application using Entity Framework. All my views use
I have a Django project, that has a Address model. This is used in
I'm trying to have just one link on my website that links to the
I have two forms on a single page. One is just a form for

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.