472,805 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 1726


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mark | last post by:
Hi there On this page i get some errors when validating: http://www.keyone.nl/lab/beeldlijn/nl/collection.asp The problem is caused by the use of ASP in my pages. This is the code: <a...
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
4
by: Eric | last post by:
Is there a way to cancel the validating event on the closing event? I have 2 textboxes that I use the validating event to check for numeric data. If I try to close the form without putting a...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
2
by: craig.wagner | last post by:
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...
5
by: robert | last post by:
Turning algs for old NumPy modules into numpy code I suffer from this: Upon further processing of returns of numpy calculations, lots of data in an apps object tree will become elementary numpy...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
2
by: lrheeza | last post by:
Hello everyone, I am a newbie at MS Access and I need help!!! I am importing an excel file using Import functionality in MS Access, all the fields are required but there are instances in the...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.