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
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

Nested Definitions

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

Occurrence

Required, Optional, Repeated+, Repeated*

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
    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.

Structs

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

Predefined Value Types

Integers

Signed: int

Unsigned: uint

Numbers

number

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
  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

Ordered Child Nodes

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

Extends

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

Schema of SML Schema

# Work in progress
Schema
  Element
    Name Schema
  End
End