SQL Server - XML验证:无效的简单类型值

时间:2021-08-01 16:04:43

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:

我正在尝试针对SQL Server 2005中的XML Schema验证XML输入,并在验证电子邮件时收到错误:

Msg 6926, Level 16, State 1, Line 4

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]

XML验证:无效的简单类型值:'john_doe@yahoo.com'。位置:/:xxx [1] /:yyy [1] / *:电子邮件[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).

每个与正则表达式匹配的电子邮件地址都被认为是有效的,除了带有下划线的内容(johnDoe@yahoo.com没问题,john.doe @ yahoo.com没问题,但john_doe@yahoo.com不是)。

If I remove the underscore the XML is validated.

如果我删除下划线,则验证XML。

I've tested my regexp (which is the one you can find on MSDN for validating emails) with various tools and they all say it's valid. But not SQL Server.

我用各种工具测试了我的regexp(你可以在MSDN上找到用于验证电子邮件的那个),他们都说它有效。但不是SQL Server。

Why does it not validate underscores? Is there something special I must do in SQL Server?

为什么不验证下划线?我在SQL Server中必须做些什么特别的事情吗?

1 个解决方案

#1


2  

Found a link about the issue with a workaround. http://www.agilior.pt/blogs/rodrigo.guerreiro/archive/2008/11/14/5965.aspx

通过变通方法找到有关该问题的链接。 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.

显然\ w应该包括下划线,除非涉及处理XSD架构。所以这不是特定的SQL Server问题。使用XMLSpy验证XML时,我有完全相同的行为。

#1


2  

Found a link about the issue with a workaround. http://www.agilior.pt/blogs/rodrigo.guerreiro/archive/2008/11/14/5965.aspx

通过变通方法找到有关该问题的链接。 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.

显然\ w应该包括下划线,除非涉及处理XSD架构。所以这不是特定的SQL Server问题。使用XMLSpy验证XML时,我有完全相同的行为。