XSD 字符集的字符串限制

XSD string restriction to charset

我们为我们的应用程序定义了一个 SOAP 接口。几乎任何字符串值都可以是任何 Unicode 字符,除了一些遗留字段值,其中只接受 Latin-1 字符集的子集。

是否可以在 XSD 架构中定义对字符串值的限制,使其仅包含来自 Latin-1 字符集的字符?

当然

<xs:restriction base="xs:string">
  <xs:pattern value="(\p{IsBasicLatin}|\p{isLatin-1Supplement})*"/>
</xs:restriction>

或者(对于 XML 1.0 中允许的字符)

<xs:restriction base="xs:string">
  <xs:pattern value="[\t\r\n&#x20;-&#xff;]*"/>
</xs:restriction>