Solved

Blank Dates in xsd

Posted on 2002-05-02
5
478 Views
Last Modified: 2012-06-21
Is there a way to allow blank dates in xsd schema validation?

I have an attribute named DateOfBirth type = xsd:date and I may or may not have any data to put into it. The schema currently says this attribute is required but won't accept and date of "" or " ". Is the only solution to alter the scehma to make is not required and just not populate the attribute if I don't have a date of birth on my database?

Dave
0
Comment
Question by:howesd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:hohndove
ID: 6986238
Hi, Howesd!

What, if any, errors are you seeing?  I used the following Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://www.people.org"
      xmlns="http://www.people.org"
      elementFormDefault="qualified">

  <xsd:element name="people">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="person" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

  <xsd:element name="person" type="personType"/>

  <xsd:complexType name="personType">
    <xsd:attribute name="name" type="xsd:string" use="required"/>
    <xsd:attribute name="dob" type="xsd:date" use="required"/>
  </xsd:complexType>
</xsd:schema>

Using this Schema, I was able to create the following XML document:

<?xml version="1.0" encoding="UTF-8"?>
<people     xmlns="http://www.people.org"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.people.org test.xsd">

  <person name="Sam Smith" dob="1954/02/01"/>
  <person name="John Doe" dob=""/>
</people>

This XML validated for me with no errors, but I do get an error if I omit the dob attribute.  Does your Schema and XML look like this?

     -Jesse
0
 
LVL 1

Author Comment

by:howesd
ID: 6986288
Jesse

Our schema is quite similar to what you had - in the end we got round the problem by defining a new type as a union between a date field and an enumerated value that allows a space. It works OK. I can't take the credit for finding out how to do this - it was my mate Dave who sussed it

Dave



- <xsd:simpleType name="bslDate">
- <xsd:union>
- <xsd:simpleType>
  <xsd:restriction base="xsd:date" />
  </xsd:simpleType>
- <xsd:simpleType>
- <xsd:restriction base="xsd:token">
  <xsd:enumeration value="" />
  </xsd:restriction>
  </xsd:simpleType>
  </xsd:union>
  </xsd:simpleType>
0
 
LVL 6

Expert Comment

by:Wayne Bradney
ID: 6997005
hohndove,

Looks like your parser is broken (or at least non-conforming). xsd:date should ONLY allow strings of the format CCYY-MM-DD. Empty strings are not allowed.

The relevant section of the spec is at:
http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/#date

howesd's solution is the typcial way to get around these kinds of restrictions, although it's much simpler (and semantically cleaner) to make the entire attribute optional, and infer from the fact that it's not present in the instance document that no date has been specified. If the attribute is present, then it MUST conform to the CCYY-MM-DD format.

Regards,
WMB
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10298593
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ / Refund points

Please leave any comments here within the next four days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

rdcpro
EE Cleanup Volunteer
0
 

Accepted Solution

by:
amp072397 earned 0 total points
ID: 10338339
PAQed, with points refunded (100)

amp
Community Support Cleanup Moderator
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question