Validating XML (empty dateTimes & numerics)

Discussion in 'XML' started by craig.wagner@gmail.com, Feb 8, 2006.

  1. Guest

    I have an element in my schema defined as follows:

    <xs:element name="BillingDate" type="xs:dateTime" nillable="true"
    minOccurs="0"/>

    I use the schema to validate incoming documents using an
    XmlValidatingReader in .NET 1.1.

    If the document contains the above element with no data, for example:

    <BillingDate></BillingDate>
    <BillingDate/>

    The validation throws an exception on this element telling me it
    contains data that doesn't conform to the type. That kind of makes
    sense, because the value in the above case is an empty string, and
    that's not a valid date.

    I can change the above tags to one of the following and then it passes
    validation:

    <BillingDate xsi:nil="true"></BillingDate>
    <BillingDate xsi:nil="true"/>

    I can also get rid of the element completely and it passes validation
    (because minOccurs="0").

    However, I would prefer to not have to go through every document
    looking for empty tags and adding the xsi:nil="true" attribute or
    removing them from the document.

    The same thing happens with elements defined as numeric types (e.g.
    xs:int).

    Is there any way (other than the above identified solutions) to get the
    validation process to pass these elements without an exception?
     
    , Feb 8, 2006
    #1
    1. Advertising

  2. wrote:


    > Is there any way (other than the above identified solutions) to get the
    > validation process to pass these elements without an exception?


    If you try to define your own type as a union of say xs:dateTime and an
    empty string then it should work. But if you use the predefined types
    then you have to use xsi:nil="true" to allow an empty element.


    <xs:element name="date" maxOccurs="unbounded">
    <xs:simpleType>
    <xs:union>
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:minLength value="0" />
    <xs:maxLength value="0" />
    </xs:restriction>
    </xs:simpleType>
    <xs:simpleType>
    <xs:restriction base="xs:date" />
    </xs:simpleType>
    </xs:union>
    </xs:simpleType>
    </xs:element>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 8, 2006
    #2
    1. Advertising

  3. Guest

    That did the trick. Thanks.
     
    , Feb 8, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manzanita
    Replies:
    3
    Views:
    6,109
    Oleg Trott
    Feb 20, 2004
  2. Micah
    Replies:
    2
    Views:
    326
    Jacek Dziedzic
    Apr 28, 2004
  3. Nick Maclaren

    Numerics, NaNs, IEEE 754 and C99

    Nick Maclaren, Jun 14, 2006, in forum: Python
    Replies:
    33
    Views:
    1,001
    Grant Edwards
    Jun 15, 2006
  4. kj

    Numerics question

    kj, Jul 2, 2010, in forum: Python
    Replies:
    1
    Views:
    350
  5. Sue
    Replies:
    2
    Views:
    173
Loading...

Share This Page