不允许空字符串的 XML 模式限制模式 [英] XML schema restriction pattern for not allowing empty strings
问题描述
在我的 XML 模式中,我有不想为空的字符串类型元素(如果它包含空格等,我也认为它是空的)
In my XML schema I have element of type string that I don't want to be empty (if it contains white-spaces etc I also consider it empty)
我在 http://blogs.msdn.com/b/neerajag/archive/2005/08/12/450723.aspx
<xsd:restriction base = "xsd:string">
<xs:minLength value="1" />
<xs:pattern value=".*[^\s].*" />
</xsd:restriction>
那个模式到底做了什么,会做什么我期望的?
What exactly does that pattern do and will do what I expect?
推荐答案
这不正是您想要的吗?
<xs:restriction base="xs:token">
<xs:minLength value="1"/>
</xs:restriction>
如果字符串仅包含空格(换行、回车、制表符、前导和尾随空格),处理器将删除它们,因此验证将失败;如果还有其他事情,验证就会成功.(但请注意:两个或多个空格的内部序列将被删除 - 请确保您对此感到满意)
If the string contains only whitespace (line feeds, carriage returns, tabs, leading and trailing spaces), the processor will remove them so validation will fail; if there's anything else, validation will succeed. (note though: internal sequences of two or more spaces will be removed - make sure you're ok with that)
这篇关于不允许空字符串的 XML 模式限制模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!