Groups | Blog | Home
all groups > dotnet xml > december 2005 >

dotnet xml : XML Validation in .NET


Francois Malan
12/19/2005 11:28:07 PM
Hi

In a schema, I have an element definition as follow:

<xs:element name="XDateTime" nillable="true" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:dateTime">
<xs:pattern value="\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}
\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>


The idea is that a dateTime value in the XML document can be stored as:
YYYY-MM-DD HH:MM:SS instead of YYYY-MM-DDTHH:MM:SS

Now, when validating an XML file with this dateTime, it validates fine
in XMLSpy, but not under .NET. It appears that the .NET validator
completely ignores the xs:pattern part, even though the definition on
http://www.w3.org/TR/xmlschema-2/#dateTime specifies that a xs:dateTime
field can have a xs:pattern constraint.

It seems as though the xs:pattern definitions are ignored by .NET.

After some experimenting, I found that only MSXML version 6 correctly
validates using this schema.

Has anyone had any experience with this or similar issues under .NET?
Is there any way that I can "tune" the validator in .NET from my
application?

Using .NET 1.1 (with SP1)


Thank you

--
Rob
12/20/2005 6:00:03 AM
[quoted text, click to view]

Curious... You could remove the pattern from the schema and deserialize it
as a DateTime object in .Net. Then you can print it out in any format you
want. There is really no need for a pattern there, as it only restricts your
input to that specific format, rejecting all other dateTime formats.

But yes, that sounds like a bug to me. Sorry I can't help you with your
original problem.

Francois Malan
12/20/2005 6:12:51 AM
[quoted text, click to view]

Thanks for the information.

--
AddThis Social Bookmark Button