Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xquery/simpletype

simple datatype validation with schematron
https://github.com/xquery/simpletype

Last synced: about 2 months ago
JSON representation

simple datatype validation with schematron

Awesome Lists containing this project

README

        

# simpletype

When I start a project, its useful to be able to validate against XML
Schema primitive datatypes, without having to fully drink the XML
Schema koolaid.

By using a [schematron](http://en.wikipedia.org/wiki/Schematron) wrapper and a simple `st:type` attribute in my
xml I can achieve simple type validation as well as provide good
abstraction for any future validation (be it schematron asserts or XML
Schema).

This can probably be characterised as a 'tactical' approach to
validation .. I am fully aware of
[NVDL](http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCIQFjAA&url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FNamespace-based_Validation_Dispatching_Language&ei=IqlNUIiHKs3IswajrYCADg&usg=AFQjCNFIkNLDK-jtAgeGr8dx0_dcPgwyVQ&sig2=B6M5nSR7p0xZawDvbSSexA)
and the goodness of [XML Schema
v1.1](http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCoQFjAA&url=http%3A%2F%2Fwww.xmlprague.cz%2F2012%2Fpresentations%2FWhats_new_3.0_XPath_XSLT_XSD_1_1.pdf&ei=tqdNUMyQIIrLswaWgoGACg&usg=AFQjCNFkn0VVtYHo7WyVxZ05wQFDHZHuYA&sig2=RHh_2_vwUDquW0J0bDcXhQ])
but every once in a while this approach suits me.

Schematron simpletype schema takes advantage of 'castable as' idiom;

```




not a xs:string


not an xs:integer


not xs:boolean


not a xs:decimal


not an xs:float


not an xs:double


not an xs:duration


not an xs:dateTime


not an xs:time


not an xs:date


not an xs:gYearMonth


not an xs:gYear


not an xs:gMonthDay


not an xs:gDay


not an xs:gMonth


not an xs:hexBinary


not an xs:base64Binary


not an xs:anyURI


not an xs:QName


not an xs:NCName

```

To use in your xml, just declare the `st` namespace and apply an
`st:type` to an element.

```

1a2 watch spot run
12

```

The limitations of this approach is that you are not applying types to
attributes (fine with me).

## Using

First you must [install schematron](http://www.bentoweb.org/refs/TCDL2.0/tsdtf_schematron.html)

To demonstrate run schematron, validating tests.xml with simpletype.sch