Work-in-progress
Validating SML document
Questions a schema answers:
Predefined types: string, number (integer, decimal), boolean, date, time, datetime (time zones), duration, binary, uri, ... (restrictions: range (min / max values), maximum / minimal length, precision, exclusion, inclusion), nullable?
Default values, enumeration, regular expressions (pattern), any / all / choice / sequence
Localization
Simplest example of an SML document, with only a root element:
MyRootElement End
The schema to validate this document would look like this:
Schema Element Name MyRootElement End End
If more than one Elements are on the root level, the root element must be explicitly specified:
Schema Element Name MySubElement End Element Name MyRootElement UnorderedContent Element MySubElement Optional End End RootElement MyRootElement End
Example:
MyRootElement MySubElement End End
Schema Element Name MyChildElement1 Definitions Element Name ChildElement End End UnorderedContent Element ChildElement Required End End Element Name MyChildElement2 Definitions Element Name ChildElement End End UnorderedContent Element ChildElement Required End End Element Name MyRootElement UnorderedContent Element MyChildElement1 Required Element MyChildElement2 Required End End End
Example SML:
MyRootElement MyChildElement1 ChildElement End End MyChildElement2 ChildElement End End End
Required, Optional, Repeated+, Repeated*
Message Example:
Message From Andrew To James Timestamp 2021-01-02 15:43 Text "I'll be there at 5pm" End
Schema:
Schema Element Name Message UnorderedContent Attribute From Required String Attribute To Required String Attribute Timestamp Required DateTime Attribute Text Required String End End End
String is predefined value type. DateTime is predefined struct.
Schema Struct Name AmountUnit Value Amount Required UInt Value Unit Optional String End Element Name MyRootElement UnorderedContent Attribute Name Required String Attribute NullableName Required String? Attribute NamesOrNull Required String[1..N]? Attribute TwoNames Required String[2] Attribute TwoOrThreeNames Required String[2..3] Attribute Amount Repeated* AmountUnit End End End
Structs can only be used in arrays if they don't contain optional values
Schema Struct Name Vector2D Value X Required Number Value Y Required Number End Element Name MyRootElement UnorderedContent Attribute Points Required Vector2D[1..N] End End End
Example:
MyRootElement Points 1.0 0.0 -1.0 0.5 End
Signed: int
Unsigned: uint
number
bool: true or false. Case-insensitive (TRUE, true, True)
string
Base64
uri
Append question mark to allow null values. By default no null value.
Define min/max size
Custom enumeration value type:
Schema EnumType Name MyEnumValueType Values Apple Banana Orange End Element Name MyRootElement UnorderedContent Attribute MyAttribute Required MyEnumValueType End End End
Example:
MyRootElement MyAttribute Apple # Banana or Orange End
Enumeration is case-insensitive by default.
Custom string value type:
Schema StringType Name MyString MinLength 5 MaxLength 8 End Element Name MyRootElement UnorderedContent Attribute MyAttribute Required MyString End End End
Length, MaxLength, MinLength, Pattern
Custom number value type:
Schema NumberType Name MyNumberValueTypeType Min 0 Max 100 End Element Name MyRootElement UnorderedContent Attribute MyAttribute Required MyNumberValueTypeType End End End
Max, Min, MaxFractionDigits
By default the order of child nodes is unordered. If order is significant it must be specified explicitly.
List
Schema Element Name MyRootElement Definitions Element Name ElementA End Element Name ElementB End Attribute Name AttributeA DataType Number End End ListContent Element ElementA Element ElementB Attribute AttributeA End End End
Example:
MyRootElement ElementB End ElementB End AttributeA 123 ElementA End AttributeA 234 ElementB End End
Sequence
Schema Element Name MyRootElement Definitions Element Name BaseElement UnorderedContent Attribute Name Required String End End Element Name MyElement Extends BaseElement End End UnorderedContent Element MyElement Required End End End
Example:
MyRootElement MyElement Name MyName End End
# Work in progress Schema Element Name Schema End End