"OR" Restriction on XSD - xsd

I have a restriction that must be :
4 digits or 0.
the values must be 4 ditits number or the number 0- the answer "refuse to answer".
i know how to make each restriction separatly but not together in the same elemnt.
can you help me ?
thank you

You can use a regular expression pattern to create your 2 options of 1 digit range 0 or 4 digits and I assume range 0-9 for each since you didn't specify.
<xs:element name="foo">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:pattern value="[0]|[0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

Related

XSD check if value is alphabetic order sorted

I am stuck on an XSD check, I need to check if a code composed of 4 letters is valid, the first and the second two letters must be in alphabetic order example:
ABCD or CDAB or EFBC etc...
And letters cannot be repeated.
I've got this so far:
<xs:simpleType name="NameAddress">
<xs:restriction base="xs:string">
<xs:minLength value="0"/>
<xs:maxLength value="4"/>
<xs:pattern value="(A){0,1}(B){0,1}(C){0,1}(D){0,1}(E){0,1}(F){0,1}(G){0,1}(H){0,1}(J){0,1}(K){0,1}(L){0,1}(M){0,1}(P){0,1}(Q){0,1}(R){0,1}(S){0,1}"/>
</xs:restriction>
</xs:simpleType>
But it only checks the alphabetic order in the sequence so if I write ABCD or CDEF it works, but it doesn't look behind and CDAB will fail.
Is there any way to perform this?
Thanks to all!

XSD restriction with mathematical constants

My question is quite straight-forward. With XSD, is it possible to restrict a value with mathematical constants like PI. For example, when you want a radian value between 0 and PI.
If not, is there an elegant and simple way to do it ?
Thank you for your help.
You can define a simpleType with the range you want:
<xs:simpleType name="radianType">
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="3.14159265358979323846"/>
</xs:restriction>
</xs:simpleType>
And reuse it in elements and attributes:
<xs:element name="horizon" type="radianType"/>

how to provide unit values with mininclusive and maxinclusive values

I have one DTD
<parameter name="ReferenceSignalPower" access="readWrite">
<syntax>
<int>
<range minInclusive="-60" maxInclusive="50" />
<units value="dBm">
</units>
</int>
</syntax>
</parameter>
I am new to XML schema i am not aware how to provide unit values with this XML schema
<xs:element name="ReferenceSignalPower">
<xs:simpleType>
<xs:restriction base="xs:unsignedInt">
<xs:minInclusive value="-60"/>
<xs:maxInclusive value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XML schemas do not have a concept of measurement units, you can define an XML attribute or XML element to contain numbers with certain restrictions (or other standard data-types like dates etc.), but it is the responsability of the application that reads the XML to interpret such numbers as values in a specific unit of measure.
If you want to add measurement unit information in the schema you can do it using the appInfo element - e.g.:
<xs:element name="ReferenceSignalPower">
<xs:simpleType>
<xs:annotation>
<xs:appinfo>
<units value="dBm"/>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:int">
<xs:minInclusive value="-60"/>
<xs:maxInclusive value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
but then you'll have to parse and interpret this information yourself.
You don't say what your question is, but I suppose the question is "why does this not work?"
Your declaration is almost right, but not quite. Why are you using unsignedInt as your base type, when you want a minimum value of -60? The minimum value of unsignedInt is already set to zero.
The XSD spec assumes that if you attempt to set a minimum value to a value that's not part of the value space of your type, then there is an error somewhere.
So: either use a signed integer type as your base type, or set the minimum value to a value that is actually present in the base type.

How to describe math formula by using xsd?

i"m trying to validate if an xml element is a multiply of 5 by using xsd. does any 1 have an idea how to do it ?
Thanks,
Itay
I'm pretty sure you can't use general formula for validation. But in your specific case you can use a pattern match to match multiples of 5
<xs:element name="myelement">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]*[05]{1}"></xs:pattern>
</xs:restriction>
</xs:simpleType>
</xs:element>

Xsd, Validate empty or minimum length string

Currently I have an Xsd validating with this rule
<xs:simpleType name='shipTo'>
<xs:restriction base='xs:string'>
<xs:minLength value='6'/>
</xs:restriction>
</xs:simpleType>
I need to allow blanks as well, but if a value is entered, it's minimum length should still be 6.
Can I do this without resorting to this xs:pattern and regex?
<xs:simpleType name='shipTo'>
<xs:restriction base='xs:string'>
<xs:pattern value='^(?:|[\w]{6,})$'/>
</xs:restriction>
</xs:simpleType>
The regex will work, but you should really make the element that you will be assigning shipTo to optional, and not include it in the XML file if it has no value.

Resources