Stenway Developer Network

SML Schema

Work-in-progress

Validating SML document

Questions a schema answers:

  • What is the name of the root element?
  • Which elements and attributes can or must an element contain?
  • How often can or must they appear?
  • Is the order significant or not?
  • Which values and how many can or must an attribute have?
  • Are null values allowed?

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

Root Element

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
  RootElement MyRootElement
End

IDs and Names

To define elements with different IDs but the same name use the name attribute:

Schema
  Element
    ID MyRootEl1
    Name MyRootElement
  End
  Element
    ID MyRootEl2
    Name MyRootElement
  End
  RootElement MyRootEl1
End

If no attribute is set the ID will be taken as name.

Attributes

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
    RequiredAttribute From
    RequiredAttribute To
    RequiredAttribute Timestamp
    RequiredAttribute Text
  End
  Attribute From String
  Attribute To String
  Attribute Timestamp DateTime
  Attribute
    Name Text
    Type String
  End

  RootElement Message
End

String is predefined value type. DateTime is predefined struct.

Structs

Schema
  Element
    Name MyRootElement
    RequiredAttribute Name
    RequiredAttribute NullableName
    RequiredAttribute Names
    RequiredAttribute TwoNames
    RequiredAttribute TwoOrThreeNames
    RepeatedAttribute* Amount
  End
  Attribute Name String
  Attribute NullableName String?
  Attribute Names String[1..N]?
  Attribute TwoNames String[2]
  Attribute TwoOrThreeNames String[2..3]
  Attribute Amount AmountUnit
  Struct
    Name AmountUnit
    Value Amount UInt
    OptionalValue Unit String
  End
  
  RootElement MyRootElement
End

Predefined Value Types

Integers

Signed Integers

Type Size Smallest Biggest
int8 1 Byte -128 127
int16 2 Byte -32,768 32,767
int32 4 Byte -2,147,483,648 2,147,483,647
int64 8 Byte -9,223,372,036,854,775,808 9,223,372,036,854,775,807

Unbound: int

Unsigned Integers

Type Size Smallest Biggest
uint8 1 Byte 0 255
uint16 2 Byte 0 65,535
uint32 4 Byte 0 4,294,967,295
uint64 8 Byte 0 18,446,744,073,709,551,615

Unbound: uint

Floats

Floats:

Type Size Smallest Biggest
float32 4 Byte
float64 8 Byte

Boolean

bool: true or false. Case-insensitive (TRUE, true, True)

Date and Time

String

string

Binary

Base64

URI

uri

Nullable

Append question mark to allow null values. By default no null value.

Arrays

Define min/max size

Predefined Structs

DateTime

Custom Value Types

Custom enumeration value type:

Schema
  Element
    Name MyRootElement
    RequiredAttribute MyAttribute
  End
  Attribute MyAttribute MyEnumValueType
  ValueType MyEnumValueType Enum Apple Banana Orange
  
  RootElement MyRootElement
End

Example:

MyRootElement
  MyAttribute Apple # Banana or Orange
End

Enumeration is case-insensitive by default. To get a case-sensitive enum use CsEnum

Grammar-Based Custom Value Type

Embed a GrammarSML description

Schema
  Element
    Name MyRootElement
  End
  Attribute MyAttribute MyCustomValueType
  ValueType
    Name MyCustomValueType
    Grammar
      Chars
        <DigitChar>   Range 0 9
        <LetterChar>  Range A Z
      End
      Tokens
        <Prefix>      <LetterChar> <LetterChar> <LetterChar>
        <Number>      <DigitChar> <DigitChar> <DigitChar> <DigitChar> 
      End
      Syntax
        <Identifier>  <Prefix> <Number>
      End
      RootRule <Identifier>
    End
  End
  
  RootElement MyRootElement
End

Example:

MyRootElement
  MyAttribute ABC1234 # or XYZ9482, ...
End

Localization

Schema
  Languages EN DE
  DefaultLanguage EN
  Element
    Name Data
    LocalizedName DE Daten
  End
  RootElement Data
End

Namespaces

IDs are prefixed with namespace ID:

Schema
  Namespace
    Prefix Ns1
    Element
      Name MyElement
      RequiredAttribute MyAttribute
      RequiredElement Ns_MyElement
    End
    Attribute MyAttribute String
  End
  Namespace
    Prefix Ns_
    Element
      Name MyElement
      RequiredAttribute MyAttribute
    End
    Attribute MyAttribute String
  End
  RootElement Ns1MyElement
End

Ordered Child Nodes

Sequence