470,810 Members | 1,397 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Validating XML (empty dateTimes & numerics)

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 '06 #1
2 1620


cr**********@gmail.com 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/
Feb 8 '06 #2
That did the trick. Thanks.

Feb 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Eric | last post: by
19 posts views Thread by Dennis | last post: by
1 post views Thread by =?Utf-8?B?bGpsZXZlbmQy?= | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.