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)
I applied restrinction I found at 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?
To limit the length of a value in an element, we would use the length, maxLength, and minLength constraints.
An XSD defines the structure of an XML document. It specifies the elements and attributes that can appear in an XML document and the type of data these elements and attributes can contain. This information is used to verify that each element or attribute in an XML document adheres to its description.
Enumerations are a base simple type in the XSD specification containing a list of possible values. Single-valued enumerations are shown as restrictions of the base simple type xs:token , as illustrated below: ? < xs:simpleType name=”GraduationPlanTypeMapType”>
doesn't this do exactly what you want?
<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)
The pattern:
.*
(.
matches any character).\s
is whitespace, so [^\s]
is "match something that isn't a whitespace. The initial ^
in the match negates the normal match any one of these characters.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With