HOW to representing NULL for dateTime?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pet Matrix.

    HOW to representing NULL for dateTime?

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

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

    #2
    Re: HOW to representing NULL for dateTime?

    "Pet Matrix." <PetMatrix@disc ussions.microso ft.com> wrote in message news:B84E0BD9-CB9E-47BE-9717-BA8836B5CCD6@mi crosoft.com...[color=blue]
    > I am having the schema and one element in that schema is ,
    > <xs:element name="EndT" type="TstampTyp e" minOccurs="1" maxOccurs="1"/>
    >
    > How do I represent the NULL value for the datatype dateTime in the xml.[/color]

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

    <xs:element name="EndT" type="TstampTyp e" 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="TstampTyp e" 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,



    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.MinVal ue or
    DateTime.MaxVal ue. 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.Sql Types.SqlDateTi me which has a field equating to
    Null and an IsNull property, befiting the trilevel-logic found in relational
    databases.


    Derek Harmon


    Comment

    • Pet Matrix.

      #3
      Re: HOW to representing NULL for dateTime?

      Thanks Derek.

      "Derek Harmon" wrote:
      [color=blue]
      > "Pet Matrix." <PetMatrix@disc ussions.microso ft.com> wrote in message news:B84E0BD9-CB9E-47BE-9717-BA8836B5CCD6@mi crosoft.com...[color=green]
      > > I am having the schema and one element in that schema is ,
      > > <xs:element name="EndT" type="TstampTyp e" minOccurs="1" maxOccurs="1"/>
      > >
      > > How do I represent the NULL value for the datatype dateTime in the xml.[/color]
      >
      > The common practice is probably to change the minOccurs="1" to minOccurs="0",
      > making the element, EndT, optional.
      >
      > <xs:element name="EndT" type="TstampTyp e" 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="TstampTyp e" 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.MinVal ue or
      > DateTime.MaxVal ue. 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.Sql Types.SqlDateTi me which has a field equating to
      > Null and an IsNull property, befiting the trilevel-logic found in relational
      > databases.
      >
      >
      > Derek Harmon
      >
      >
      >[/color]

      Comment

      Working...