XSD multiple conditions - xsd

I have an XML schema with the following piece of code:
<xs:attribute name="extension" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="((18)|(19)|(20))[0-9][0-9]((0[1-9]|1[0-2]))((0[1-9]|1[0-9]|2[0-9]|3[0-1]))" />
</xs:restriction>
<xs:length value="8" />
</xs:simpleType>
</xs:attribute>
This piece of code determines if a date of birth of people alive is correct or not. It is given that anybody is born in any year starting with 18, 19 or 20. Then followed by any two numbers, a month between 01-12 and a day between 01-31. The date of birth must contain 8 numbers to validate.
The question is if there is any way to develop this further? For instance if there is a year of birth 1809, it will validate even though it is impossible for someone in that age to be alive. Also a year in the future will validate - say 2058.
I there a way to put like "minyear" and "maxyear" where the first 4 numbers of the string cannot be less than $minyear or and greater than $maxyear?
I may also add that in direct connection with this 8 number string comes additional four numbers that are controlfigures and has nothing to do with years, month and day. That is why the base is string.
Any ideas?
/Paul

Got this far:
<xs:attribute name="extension" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(([1][8][9][0-9]|[1][9][0-9][0-9]|[2][0][0-1][0-9])(0[1-9]|1[0-2]))((0[1-9]|1[0-9]|2[0-9]|3[0-1]))" />
</xs:restriction>
<xs:length value="8" />
</xs:simpleType>
</xs:attribute>
This piece of code will restrict valid years from 1890 until 2019. The only problem is that the year 2019 will pass, besides that it works.
However it is not perfection and when the year 2020 comes it will let pass all years up to 2029, so is there a way to rule out that imperfection?
/Paul

Yes! Solved:-)
The pattern section should be like this:
<xs:pattern value="(((189)[0-9]|(19)[0-9][0-9]|((200)[0-9]|(201)[0-8]))(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1]))" />
This works in XML Schema 1.0. Perhaps there is a slicker solution in 1.1?
/Paul

Related

XSD Validation - Allow All Except String That Contains

Quite new at XSD validations.
Is there any way at all to validate string values - to allow all values a user may enter except certain values that contain a keyword.
For example, I have a system that users can submit their names.
I want to allow any name that comes through except for strings that contain 'Joh'
i.e. Allow Mary, Eric, Simon, etc and reject John, Johan, Bjohn, Benjoh, etc
So in my understanding (coming from PHP), 'Not Equal To' is '!=' but this wouldn't work here.
And wildcards wouldn't work as for any values that contain 'joh' as '%joh%'
<xs:element name="Names">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value!="%joh%"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Is there anyway around this?

SOAP UI - <xs:choice> and <xs:element> as siblings under <xs:sequence> not interpreted correctly

I am using SOAPUI for sending SOAP requests to my web service.
When I have <xs:choice> and <xs:element> as siblings under <xs:sequence>, the choice element does not appear as a combo box, instead appears as sequence of elements.
In this case, my SOAP request in SOAPUI shows all the elements ignoring <xs:choice>.
Please let me know if somebody ran into this problem and got any solution
What I understand you are looking for is numerated list
Like this
<xs:simpleType name="regularType">
<xs:restriction base="xs:token">
<xs:enumeration value="yes"/>
<xs:enumeration value="no"/>
</xs:restriction>
</xs:simpleType>
and add as many choices as you need.
Edit: I know it's 4 months old question, but I guess someone in the future might benefit from this.

How do I make use of new Azure role sizes?

New Azure role sizes were announced recently and I want to test my service on STANDARD_D1. So I open my service definition file which starts something like this
<ServiceDefinition name="MyService"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"
schemaVersion="2012-10.1.8">
<WebRole name="Whatever" vmsize="Small">
and change Small to STANDARD_D1. The definition now fails validation - STANDARD_D1 is not supported by the schema version I use.
It looks like perhaps my Azure SDK version is "too old" but.. Suppose I update to a later SDK version and then some new "sizes" appear - will I have to update again or is there any way to make use of new "sizes" without updating the SDK?
How do I make it work? Do I have to update to a newer SDK or is there perhaps some workaround?
Just update the SDK, I did this and worked first time after having the same issue as you.
I haven't tried it (so I may be wrong) but can you try some hack? Basically the schema is validated via schema definition file stored in C:\Program Files\Microsoft SDKs\Windows Azure\.NET SDK\[your SDK version]\schemas folder (ServiceDefinitionSchema.xsd). Can you try by changing that file to include your desired VM size in there? The node you want to manipulate is RoleSize:
<xs:simpleType name="RoleSize">
<xs:restriction base="xs:string">
<xs:enumeration value="ExtraSmall" />
<xs:enumeration value="Small" />
<xs:enumeration value="Medium" />
<xs:enumeration value="Large" />
<xs:enumeration value="ExtraLarge" />
<xs:enumeration value="A5" />
<xs:enumeration value="A6" />
<xs:enumeration value="A7" />
<xs:enumeration value="A8" />
<xs:enumeration value="A9" />
</xs:restriction>
</xs:simpleType>
Please give it a try and let me know if that works. If not, then I will delete my answer.

How to generate a 'HTML select' from XSD definition

I try to generate HTML code from XSD and plan to generate a selection with defined values.
I could use a restriction in XSD but I need the values of the options too.
<select name="Pizza" size="5">
<option value="P101">Pizza Napoli</option>
<option value="P102">Pizza Funghi</option>
</select>
What would be the proper XSD to define a HTML select with options and values?
A standard xs:restriction will allow you to mark up the values, but for the descriptions I'd just use a custom namespace on top of the schema. Something like this would do it:
<xs:element name="Pizza" xmlns:pizza="http://my.custom.namespace/pizza">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="P101" pizza:description="Pizza Napoli"/>
<xs:enumeration value="P102" pizza:description="Pizza Funghi"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
XML is extensible and so therefore is XML schema.
This approach has the benefit that you can still validate data against the schema easily (a validator will simply ignore the custom namespace), but when converting to HTML, you can write out the options in the way you want.

Help in defining conditional params in WSDL

I am working on defining WSDL and it has i/p param in the operation.
WSDL will be tested by SOATest.
Query:
I have a param which is conditional and need help in defining.
I want something like this..
if Name is selected then it should force user to select LastName, else both will be null
Dummy Ex:
<xs:simpleType name="FullName">
<xs:restriction base="xs:string">
<xs:enumeration value="Name" />
<xs:enumeration value="LastName" />
</xs:restriction>
</xs:simpleType>
There is no way to do this using WSDL or XSD (which WSDL depends on).
There are sometimes hacks you can use, but they're worse than the alternative. The alternative is to simply verify in code that if Name is selected then Lastname must be supplied.

Resources