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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:58:35+00:00 2026-05-19T09:58:35+00:00

For some reason I can’t quite get nillable to work correctly with the .Net

  • 0

For some reason I can’t quite get nillable to work correctly with the .Net schema validator. I’m trying to find a way to make a parent node optional but at the same time prevent an empty node from passing through the validator.

Here’s the current element validator:

    <xs:element name="Dates" minOccurs="0" maxOccurs="1">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="From" type="datetime" minOccurs="0" maxOccurs="1" />
          <xs:element name="To" type="datetime" minOccurs="0" maxOccurs="1" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>

I’ve tried changing the Dates element to nillable=”false” but that doesn’t work — an empty node still makes it past the validator.

I’ve also tried changing all three element nodes to nillable=”false” — which works fine for detecting an empty parent node but results in both children becoming required nodes instead of remaining optional.

So am I missing something here? Yes, I can always just throw some code at it and make it work… but I’m betting that there’s a variation here in the schema declarations that will give me what I need.

  • 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-19T09:58:35+00:00Added an answer on May 19, 2026 at 9:58 am

    The solution in your case is “multiple choice”:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="root">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="Dates" minOccurs="0" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="1" maxOccurs="2">
                                <xs:choice maxOccurs="1">
                                    <xs:element name="From" type="xs:dateTime" />
                                </xs:choice>
                                <xs:choice maxOccurs="1">
                                    <xs:element name="To" type="xs:dateTime" />
                                </xs:choice>
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    valid documents

    <?xml version="1.0"?>
    <root>
        <Dates>
            <From>2010-01-20T12:34:45</From>
            <To>2011-01-20T12:34:45</To>
        </Dates>
    </root>
    
    
    <?xml version="1.0"?>
    <root>
        <Dates>
            <From>2010-01-20T12:34:45</From>
        </Dates>
    </root>
    
    
    <?xml version="1.0"?>
    <root>
        <Dates>
            <To>2011-01-20T12:34:45</To>
        </Dates>
    </root>
    

    invalid document

    <?xml version="1.0"?>
    <root>
        <Dates/>
    </root>
    

    The simple way

    <xs:element name="Dates" minOccurs="0" maxOccurs="1">
        <xs:complexType>
            <xs:sequence>
                <xs:any minOccurs="1" maxOccurs="2" processContents="lax" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    

    Where your only way of enforcing <From /> and <To /> would be using a special namespace.

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

Sidebar

Related Questions

For some reason I can't find a way to get the equivalents of sqlite's
For some reason I can't seem to get the MySQL Net Connector to work
For some reason I can't get my SVG filters to work in Firefox. They
For some reason I can't get static_dir to work. In my app.ymal I have:
For some reason I can't seem to get the basic example to work, provided
For some reason I can't get this to work at all. I have read
For some reason I can't get Basic Authentication to work using PHP on my
For some reason I can get this to work, using single proxy everything seems
For some reason I can't get the succinct flow control syntax to work with
For some reason I can't hide WPF Toolkit's DataGridColumn. I am trying to do

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.