473,473 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 24563
"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! ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.