472,794 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

HOW to representing NULL for dateTime?

Hi,
I am having the schema and one element in that schema is ,
<xs:element name="EndT" type="TstampType" minOccurs="1" maxOccurs="1"/>

How do I represent the NULL value for the datatype dateTime in the xml.
Nov 12 '05 #1
2 24301
"Pet Matrix." <Pe*******@discussions.microsoft.com> wrote in message news:B8**********************************@microsof t.com...
I am having the schema and one element in that schema is ,
<xs:element name="EndT" type="TstampType" minOccurs="1" maxOccurs="1"/>

How do I represent the NULL value for the datatype dateTime in the xml.


The common practice is probably to change the minOccurs="1" to minOccurs="0",
making the element, EndT, optional.

<xs:element name="EndT" type="TstampType" minOccurs="0" maxOccurs="1"/>

Here the answer to your question is that EndT is NULL when EndT is not present in
the instance document. If you're going to use this schema with an ADO.NET DataSet,
it will be significantly easier going on you when following this approach.

An alternative answer (albeit recognized by the specification as an out-of-band signal
to the XML consumer) is to add the nillable attribute to this element's declaration,

<xs:element name="EndT" type="TstampType" minOccurs="1" maxOccurs="1" nillable="true" />

Then within your instance document whenever the element EndT appears and it
must indicate it's value is 'null' it must appear as follows,

<EndT xsi:nil="true" />

assuming empty content is consistent with your definition of TstampType. You must
also declare the XML Schema Instance document [xsi] namespace URI somewhere
within the scope that includes EndT, i.e.,

<myDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<!-- . . . -->
<EndT xsi:nil="true" />
<!-- . . . -->
</myDocument>

For more information of xsi:nil and using nillable in your schema documents, please
see,

http://www.w3.org/TR/xmlschema-0/#Nils

The final quandry you'll find yourself in with .NET is how to represent a 'null' value
in a .NET DateTime, because the DateTime structure is a value-type (it cannot be
null). The two approaches most commonly used here are to:

1. Represent 'null' with some 'special' date such as DateTime.MinValue or
DateTime.MaxValue. Using MaxValue as the 'null' value for a DateTime
representing start/endpoints in time can be beneficial as it fits well into a
number of date range processing situations (e.g., having a defined Start-
Date and no EndDate, signifying an activity that is 'in-progress').

2. Use System.Data.SqlTypes.SqlDateTime which has a field equating to
Null and an IsNull property, befiting the trilevel-logic found in relational
databases.
Derek Harmon
Nov 12 '05 #2
Thanks Derek.

"Derek Harmon" wrote:
"Pet Matrix." <Pe*******@discussions.microsoft.com> wrote in message news:B8**********************************@microsof t.com...
I am having the schema and one element in that schema is ,
<xs:element name="EndT" type="TstampType" minOccurs="1" maxOccurs="1"/>

How do I represent the NULL value for the datatype dateTime in the xml.


The common practice is probably to change the minOccurs="1" to minOccurs="0",
making the element, EndT, optional.

<xs:element name="EndT" type="TstampType" minOccurs="0" maxOccurs="1"/>

Here the answer to your question is that EndT is NULL when EndT is not present in
the instance document. If you're going to use this schema with an ADO.NET DataSet,
it will be significantly easier going on you when following this approach.

An alternative answer (albeit recognized by the specification as an out-of-band signal
to the XML consumer) is to add the nillable attribute to this element's declaration,

<xs:element name="EndT" type="TstampType" minOccurs="1" maxOccurs="1" nillable="true" />

Then within your instance document whenever the element EndT appears and it
must indicate it's value is 'null' it must appear as follows,

<EndT xsi:nil="true" />

assuming empty content is consistent with your definition of TstampType. You must
also declare the XML Schema Instance document [xsi] namespace URI somewhere
within the scope that includes EndT, i.e.,

<myDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<!-- . . . -->
<EndT xsi:nil="true" />
<!-- . . . -->
</myDocument>

For more information of xsi:nil and using nillable in your schema documents, please
see,

http://www.w3.org/TR/xmlschema-0/#Nils

The final quandry you'll find yourself in with .NET is how to represent a 'null' value
in a .NET DateTime, because the DateTime structure is a value-type (it cannot be
null). The two approaches most commonly used here are to:

1. Represent 'null' with some 'special' date such as DateTime.MinValue or
DateTime.MaxValue. Using MaxValue as the 'null' value for a DateTime
representing start/endpoints in time can be beneficial as it fits well into a
number of date range processing situations (e.g., having a defined Start-
Date and no EndDate, signifying an activity that is 'in-progress').

2. Use System.Data.SqlTypes.SqlDateTime which has a field equating to
Null and an IsNull property, befiting the trilevel-logic found in relational
databases.
Derek Harmon

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: James | last post by:
In certain applications, it is necessary to distinguish between an emptyString vs. a null value. What is the appropriate way to make this distinction in XML? <elementName></elementName> looks...
0
by: cem marifet | last post by:
I am trying to pass in a null value into a webservice.How can this be accomplished in the raw soap message that goes to the server? I have a previous message regarding this. Thank You Cem Marifet
8
by: Manish Jain | last post by:
Platform : ASP.Net/C# void SomeFunction(DateTime date) { string text = date.ToString(); //This crashes if date is null } I am using a construct similar to above. I want to check if the date...
1
by: Dean L. Howen | last post by:
Dear friends, Could you help me to solve the problem: How can we set/get NULL values of datetime in DatetimePicker ? I design a form using DateTimePicker to input/output date value, but the date...
2
by: Fred Nelson | last post by:
Hi: Another C# newby question: How do I declare a null DateTime variable: DateTime myDate = null; I get the error:
1
by: Eric Dev | last post by:
Bonjour, Au secours aidez moi, Comment inserter une valeur nul dans un champs datetime j'ai essayé mais l'application converti automatiquement le vide en 01/01/1900 que faire ?
1
by: Brad Pears | last post by:
I am using vb.net 2005 and SQL server 2000. In my table I have a date field of type "smalldatetime". In my vb application, the user may or may not enter a date value into the appropriate text box....
4
by: jehugaleahsa | last post by:
Hello: We were hoping to allow users to have DateTimePicker value null so that a unused date is stored on a Database. Does the control support this? I am pretty sure it doesn't. How would you...
2
by: Ken Foskey | last post by:
I have a problem with the following if the EndDate on the database is Null. Knowing this I can code around it but not knowing it was a very frustrating experience! ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.