How to correctly define an element in XML schema representing a primary key implemented as autoincrementing integer number in a database table?
For example, consider table:
Person (
person_id int identity primary key,
person_name nvarchar(64) null
)
On one hand the XML schema should enforce the key person_id element (I suppose minOccurs=1, nillable=false). On the other hand new documents (yet to be persisted) should validate without the person_id element.
Do you have to use the same schema for inbound and outbound (could these be separate schemas)?
Assuming the answer to the first is yes, I’d bet tempted to make the person_id optional – because that’s what it is.
We have a rules where we use nillable=”true” in the definition of XML elements that should always be present in instances conforming to the schema. Use of xsi:nil allows a processing application to differentiate between XML instances that are unintentionally invalid against a schema, and those which have been constructed and submitted correctly, but that have information missing.
You could use nillable here, but this seems counter intuitive as really the information (at the point of loading) is not required. I would personally prefer to see two schemas – one for the “request”, one for the “response”.
Also, what is the business purpose of the schema validation? Is there a reason to have a schema post loading into the database?