Solved

Blank Dates in xsd

Posted on 2002-05-02
5
475 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
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:wbradney
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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XSL-FO - show results in 2 columns 5 32
Xsl-fo show PDF when no results are returned 2 20
what are list of ebay api errors 1 28
TSQL XML Namespaces 7 22
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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