SQL Server - XML Validation: Invalid simple type value
I'm trying to validate an XML input against an XML Schema in SQL Server 2005 and I get an error when validating the e-mail:
Msg 6926, Level 16, State 1, Line 4
XML Validation: Invalid simple type value: 'john_doe@yahoo.com'. Location: /:xxx[1]/:yyy[1]/*:Email[1]
The email field is defined in the schema as:
<xsd:simpleType name="EMailType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</xsd:restriction>
</xsd:simpleType>
Every email address that matches the regexp is considered valid except for something with underscores in it (johnDoe@yahoo.com
is OK, john.doe@yahoo.com
is OK, but john_doe@yahoo.com
is not).
If I remove the underscore the XML is validated.
I've tested my regexp (which is the one you can find on MSDN for valid开发者_开发知识库ating emails) with various tools and they all say it's valid. But not SQL Server.
Why does it not validate underscores? Is there something special I must do in SQL Server?
Found a link about the issue with a workaround. http://www.agilior.pt/blogs/rodrigo.guerreiro/archive/2008/11/14/5965.aspx
Apparently \w
should include the underscore and does so except when it comes to handling XSD schemas. So this is not a specific SQL Server problem. I have the exact same behavior when validating an XML using XMLSpy.
精彩评论