Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Blank Dates in xsd

Posted on 2002-05-02
5
Medium Priority
?
487 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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