Validating XML with empty dateTime & numeric elements

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?

0
2/8/2006 6:45:27 PM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
666 Views

Similar Articles

[PageSpeed] 20

Craig,

The following should do what you need.  This example uses a union of 
dateTime type and an empty string type.

<xs:element name="BillingDate" type="nillableDate" minOccurs="0"/>

<xs:simpleType name="nillableDate">

  <xs:union memberTypes="xs:dateTime emptyString"/>

</xs:simpleType>

<xs:simpleType name="emptyString">

  <xs:restriction base="xs:string">

    <xs:length value="0"/>

  </xs:restriction>

</xs:simpleType>


-- 
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights. 
Use of included script samples are subject to the terms specified at 
http://www.microsoft.com/info/cpyright.htm

<craig.wagner@gmail.com> wrote in message 
news:1139424327.014412.210630@f14g2000cwb.googlegroups.com...
>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?
> 


0
skits (68)
2/8/2006 7:44:34 PM
That worked perfectly. Thanks.

0
2/8/2006 9:24:27 PM
Reply:

Similar Artilces:

Msgbox entry validation
The following Macro will not loop more than twice the error entries. Will someone help me correct it to loop indefinely? Thanks Sub Entry_validation() Dim Teststring As String Dim Inputstring As String Cells(1, 1) = "ABC" 'as given filename Cells(2, 1) = "DEF" 'as given filename Cells(3, 1) = "GHI" 'as given filename Cells(4, 1) = "JKL" 'as given filename errorloop: Inputstring = InputBox(prompt:="Enter Filename" & vbLf & "Enter abort to abort en...

Data Validation -> Validation list is larger than the cell width
I have a workbook that I've just added data validation to one cell. FWIW, the data validation is based on a named range. Here's the (perceived) problem. When I've set up data validation in the past, the selection is the same width as the cell. In this case, the list starts almost a full cell width to the left. What am I missing? Thanks, Barb Reinhardt Barb, In Excel2003 I can replicate what you describe under the following conditions: 1. the named range contains entries that are wider than the data validation cell 2. The data validation cell is r...

Parsing XML in string variable?
I have a method that returns a string that contains XML, and I need to parse that string (ie. find specific keys). How can I do this? I found one that searches a Stream, but I don't know how to convert from string to stream. Thanks. hi vmi, you could use the System.Xml.XmlDocument class, simply make a new instance and use the LoadXml-Method (does not properly load string with encoding markers). You could also use the .NET 3.5 System.Xml.Linq.XElement. There are several utility classes to read from strings and streams and vice versa, e.g. System.IO.StringReader &am...

Prefer empty cell to #NA
I have a formula =INDEX($G$7:$G$42,MATCH(R54,$H$7:$H$42,0)) That returns "#NA" when the target cell is empty. I would prefer that cell to remain blank as well, any suggestions? Thanks, jsjenn --- Message posted from http://www.ExcelForum.com/ Filter it out with =IF(ISERROR(MATCH(R54,$H$7:$H$42,0)),"",INDEX($G$7:$G$42,MATCH(R54,$H$7:$H$4 2,0)))) -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "jsjenn >" <<jsjenn.10awog@excelforum-nospam.com> wrote in messa...

Insert XML string into XML File: Part 2
Thanks to some good help from a previous post, I have been able to create well formed xml as part of a report logger app. However, I still have a small problem. When I add new xml to the log file, the new nodes are appended to the original file. What I really want is for the log file to grow as "report nodes" are added. Also, I am a bit concerned about performance, particularly as the file grows in size. I must write to an xml file (vs. a database) and am trying to understand the best way to do this. I prefer to not use "temp files" and would like to just modify the ...

Validating against a DTD
Hello All, I am trying to validate an xml file against a DTD. I went through a lot of examples especially: http://www.xmlforasp.net/codebank/util/srcview.aspx?path=../../codebank/System_Xml/XmlValidatingReader/Validator/validator.src&file=validator.cs&font=3 but its not working in my case. First of all, when i try to add my DTD file in XmlSchemaCollection object, it throws an error saying DocType element is expected. I am using NITF DTD for this and there is no DocType element in it. Any help will be appreciated. Thanks. VD You should not add DTDs to XmlSchemaCollection. XmlSchema...

XML Tree Structure
Hi Folks, I would like to take a XML document and write its data into a tree structure for a custom tree control. The document has two fields with one called task (a text field) and the other called tree_level (an integer field). Consider the document to be valid and well-formed. The tree_level is an index describing where a node will reside in a tree structure. A partial view of the XML document is as follows: <task>summary task</task> <tree_level>0</tree_level> <task>task1</task> <tree_level>1</tree_level> <task>task2</task&...

Validation dropdown list is not coming visible
Hi, I'm using XP and 2003. I have a problem that I have once found resolution, but now it came again and cannot remember what needs to be done. Here is the problem: There is a column where Validation is specified in right manner with error message in case of error. When selecting the cell - dropdown list is not coming visible. In case I write something wrong it gives error message. If I recall correctly - it was something to do with some kind of list. How can I change this to work properly? I tried to paste new column from another file where the column is working as I want...

Data Validation
Hi all I want to set data validation on a cell so that it will accept the following (and only the following) text strings: (1) "BR" (literally) or (2) "NT" (literally) or (3) "nA" where n is any positive integral numerical value including zero and A may take any of the values "L", "P", "T", "V" or "Y" or (4) "An" where n is any positive integral numerical value including zero and A may take either of the values "K" or "D". Is this possible, please, and if so how? thanks -- Return e...

Sent Folders Empty
I have a user whose Sent Folder remains empty, even though the tools\options\email options\"save copies of messages in sent items folder" is enabled I am mystified. Any help would be appreciated Medman Check his views, have him select set items and then click on View-> Current view up at the top. It may be set to Unread Messages. Try setting it to just Messages. -- Dan Winter, MCSE Microsoft Exchange Support Please do not send email directly to this alias. This alias is for newsgroup purposes only. This posting is provided "AS IS" with no warranties, and confers ...

reinstall-validation problem
Hardware hit from lightning so new hd and video card and start over. All goes well with install using a slipstreamed XP-Pro SP3 disk but I notice it never asks for the Product Key during install yet it Activates itself during one of the boots and I think little of it until ... During the updates which followed (100+!!!) I notice Windows Defender doesn't seem to run or leave itself installed. As it is running on my laptop figured I just download it. When I run it, it wants to first do the Genuine Advantage bs which I let it, at which time it says "bogus". Ugh, g...

[ANN] Liquid XML Studio Released
Announcing the release of Liquid XML Studio 2008 a Freeware XML Development Environment. Download available from www.liquid-technologies.com. Key features include - An Advanced Graphical Schema Editor - XML Editor, with auto-complete, syntax highlighting & validation - Web Service Browser, supports calling Soap services - XPath Expression Builder, visualise XPath expressions - Documentation Generator, HTML Docs from your XML schemas - Code Generation, C++, C#, .Net, Java, VB .Net & VB6 (trial) Liquid XML...XML the smart way! ...

How do I indicate a empty or blank cell in an IF function?
I am trying to do a simple IF function but don't know how to indicate if a cell is empty or blank then I want a certain text value returned. What I am trying is: =IF('Sheet 1'!A15=IS NULL,"NO","YES") What I want is if the cell indicated on an other sheet is empty or blank then the word NO to appear in the formula cell and if it does have text then YES to appear. How can I do this? Hope I made myself clear enough. I couldn't figure out how to ask help the right way to get the correct answer. Thanks for all of your help! Never Mind. I seem to ha...

Validation
Julie the same can be achieve without going thru the double drop down boxes. You could do it just using the combobox alone. Thank again Please stay in the ORIGINAL thread. The archives will thank you. -- Don Guillett SalesAid Software donaldb@281.com "JLong" <anonymous@discussions.microsoft.com> wrote in message news:034101c49c3b$889b5020$a501280a@phx.gbl... > Julie the same can be achieve without going thru the > double drop down boxes. You could do it just using the > combobox alone. Thank again ...

Data Validation
I have set up a data form and have data validation rules on the various input cells. I see that there is an option called "Ignore blanks" in the data validation settings, which is supposed to restrict someone from entering past an input cell without entering valid data, if the "Ignore blanks" box is unchecked. I have tried to do this, but it does not seem to work. Please could someone tell me what I am doing wrong? Provide information, or better yet, a screen capture of the Data Validation dialog box with the Setting tab selected (User ALT+PrintScreen to copy the imag...

validating macro
Hi I am sending a spread sheet out to branchs I need them to complete a sheet (common info) before they do anything else on the workbook. I am looking for a macro or code for VBA which who check (common info) see if the cells are complete if not bring up a error screen informing the user to complete the form and then take them straight to the (common info) sheet. and if possible let them go to the tab which they want to go to. Use an extended version of something along these lines: (if there are lots of cells use a 'for row numbers x to y' or 'do until' statment, o...

How Do I parse this XML document, most efficiently?
What would be the best way to parse this XML document? I want to avoid using XMLDocument. I don't know if I should use XMLTextReader, or Xpath classes. There is only one element <MessageStore> element in the document, "always" at the end of the document. There will be thousands of <Messages> elements, "always" before <MessageStore> element. 1st Step ===== I need to get the <PR_STORE_ENTRY_ID> data "first". There will always only be one MessageStore element, with one child containing data. 2nd Step ====== I then need all the data from...

XML syntax as string
Hi I am trying to define string xml="<?xml version="1.0"?>"; But it gives error messages. Can any help me define <?xml version="1.0"?> as string... Thanks in advance Rahil string xml="<?xml version=\"1.0\"?>"; I hope it helps. >-----Original Message----- >Hi >I am trying to define >string xml="<?xml version="1.0"?>"; > >But it gives error messages. Can any help me define > ><?xml version="1.0"?> as string... > >Thanks in advance > >...

Generate XML from database and XSD files
Hi all, I have a set of XSD fiels: CSSTypes.xsd EventDetail.xsd E01_Export.xsd E02_Export.xsd E03_Export.xsd E04_Export.xsd E05_Export.xsd etc. I need to provide an exportation system of our database via external web service using sending the XML verified by the previous schemas. Any advise about how to proceed? what about XSD.EXE? is this usefull? Thank you very much, mc. ...

rules, dotnet applications and XML
<xml newbie> Hi all, We are considering using XML to specify rules, policies. This XML file will be used to generate source code in either managed C++ or C#, which will be implemention of API to be used by different applications program (written in .NET language, for this dicussion). You can contribute your ideas. Time for an example. A company or a government body has lot of policies which can be captured in the form of IF-THEN rules. These rules needs to be accomodated in application program(s). o Imagine an application program which processes visa applications, social security etc...

Reboot Validator
I'm running XP Pro, SP3. Attempting to install a program from Nero. Software keeps failing at startup, despite numerous re-installs. During installs, it keeps attempting to update the 'reboot validator' which it does not seem to be able to do. What is the reboot validator, and how do I update it. Couldn't find anything useful on MS site and Nero Tech support just says its an MS problem. -- Thank you, B. Parker Never heard of it but Nero Support should know about it: Reboot Validator appears to be a Nero component; cf. http://www.brighthub.com/comput...

Conditional validation?
Hello All I have a sheet that is essentially just columns of data (except for the column headings in the first row), and two of the columns are what I would call 'mutually exclusive': i.e. if a value is entered in a row in either column, the user must be prevented from entering any value in the same row of the other column. The two columns already have some basic validation applied (ranges of permissable numerical values), and this validation would need to be applied for any values that are entered. I am sure this can be done, but cannot see how! Hope someone can help. Many thanks L...

REPOST: dynamic validation
I think I wasn't clear that I need the Validation option under the Data menu, List, source values. That is what I am trying to fill with this equation. In other words, range1 and range2 are sets cells which contain values. I want those values to be the dropdown options in the cell based on what the previous cell to the left is selected as. So if Range1 is three cells with Tall, Dark, Handsome and Range2 is Sweet, Pretty, Nice, then based on the selection of F or M in A1, I want the choices for B1 to be one of those lists. I know that quotes are required for the IF. My probl...

Excel 2000 vs 2002 Sheet protection & Validation cells
Hello, I have an Excel spreadsheet built on Excel 2000. I have set sheet protection with password, and I have some unprotected cells with drop down menu (validation with 50 choices) Everything works very well. I sent this file to a friend who has Excel 2002. The same "unprotected" validation cells cannot be modified in his version as the message says that these cells are protected What can be done in order to make it work on his version?? I do have some "very hidden" sheet with password protected VBA properties, if that is an issue. Similarly there are some macros o...

Why can't I use XML in the Student and Teacher Edition?
Am I missing an Add-in? I can't believe I wasted my money buying this version of MS Office, when I can't even use it to complete the assignments when XML isn't available.. Any clues? Thanks, GunnyUSMCRet You've got one reply at one of your other posts. gunnyusmcret wrote: > > Am I missing an Add-in? I can't believe I wasted my money buying this version > of MS Office, when I can't even use it to complete the assignments when XML > isn't available.. > > Any clues? > > Thanks, > GunnyUSMCRet -- Dave Peterson XML is not available...