"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