473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1757


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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.