Solved

Blank Dates in xsd

Posted on 2002-05-02
5
468 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
PAQed, with points refunded (100)

amp
Community Support Cleanup Moderator
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now