Creating a new data type

This should cover W3C XML Schema, Relax NG and DTD related problems.
carol.aboody
Posts: 5
Joined: Mon Aug 13, 2007 1:04 pm

Creating a new data type

Post by carol.aboody »

Hi all

I have 2 questions on creating data types:

1)
I need my "datereturn" attribute to be in a specific format, or contain empty value.
For example: 2007-02-02 12:22:00, or "".

2)I need my "avgrank" attribute to be decimal OR empty. If i use decimal with an empty answer i get a validation error.

This is my Schema:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2007 sp2 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getrank">
<xs:complexType>
<xs:attribute name="rc" use="required" type="xs:int"/>
<xs:attribute name="datereturn" use="required" type="xs:????????"/>
<xs:attribute name="avgrank" use="required" type="xs:????????"/>

</xs:complexType>
</xs:element>
</xs:schema>
Thanks
carol.aboody
Posts: 5
Joined: Mon Aug 13, 2007 1:04 pm

Solution to empty-decimal problem,date format still an issue

Post by carol.aboody »

I found a solution to the second problem here :
http://xsd.stylusstudio.com/2003May/post03006.htm

I still need help for the date format.

Thanks
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

If you're not using the standard date format, you could create a pattern based on an xs:string, eg
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="([0-9]{4}-[0-1][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9])|"/>
</xs:restriction>
</xs:simpleType>

Can't remember if [0-9]{4} works, you might need to use [0-9][0-9][0-9][0-9]
carol.aboody
Posts: 5
Joined: Mon Aug 13, 2007 1:04 pm

Post by carol.aboody »

I tried that, i got this message:

Validation Error Message: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '.'.

I couldn't find the meaning of it.
Post Reply