Schematron

WHAT IS INSIDE?

  • XML SCHEMA LANGUAGES
  • SCHEMATRON INTRODUCTION
  • SCHEMATRON PROCESSING
  • SCHEMATRON EXAMPLE

XML SCHEMA LANGUAGES

TWO TYPES OF SCHEMA LANGUAGE  

  1. Grammar-based schema languages
  2. Rule-based schema languages

GRAMMAR-BASED SCHEMA LANGUAGES

DOCUMENT TYPE DEFINITION-DTD

  • include the definition of internal and external entities
  • schema features focus on describing elements
  • Every element and attribute used by the document type defined by the DTD must be described
  • Each element must have a content model, identifying which child elements or text nodes are allowed, as well as a list of permissible attributes, if any attributes are allowed

SCHEMA LANGUAGE

GRAMMAR-BASED

RULE-BASED

DTD

RELAX-NG

XML-SCHEMA

SCHEMATRON

SCHEMATRON INTRODUCTION

  • a rule-based language
  • uses path expressions instead of grammars
  • open schema language
  • has been designed to be implemented on XSLT
  • Way to test XML documents
  • Way to specify and test statements about your XML document
    • element
    • attribute
    • content

WHY WE USE SCHEMATRON?

  • Different requirements at different stages of the document lifecycle
  • Local or temporary requirements 
    
  • Unusual variations to manage

WHEN WE USE SCHEMATRON?

  • Validate output of a program against its input or vice versa
  • validate things schemas can’t express
  • run reports
  • find patterns in document
 
 

SCHEMATRON HIERARCHY

phases

patterns

rules

assertions/report

Activate different families at different time

Rules are grouped into families

Test are collected into rules,apply to one element

Are to be tested

SCHEMATRON PROCESSING

Schematron processors

XSLT-based

processors

XPath-based processors

PROCESSING USING XSLT

SIMILARITIES OF XSLT

<?xml version="1.0" encoding="UTF-8"?>
<books>
    <book author="Jayathilake">
        <shortstory author="Jayathilake">
            <name></name>
            <version></version>
        </shortstory>
        <novel>
            <name></name>
            <version></version>
        </novel>
    </book>
    
    <book author="Wickramasinghe">
        <shortstory>
            <name></name>
            <version></version>
        </shortstory>
        <novel>
            <name></name>
            <version></version>
        </novel>
    </book>
</books>
<xsl:template match="book">-----------------------------------similar to rule
        <xsl:if test=".[child::node()[attribute::author]]">---similar to assertion
            <xsl:message>invalid Book</xsl:message>
        </xsl:if>
        <xsl:if test=".[attribute::author]">-------------------similar to report
            <xsl:message>Valid book</xsl:message>
        </xsl:if>
</xsl:template>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    <sch:pattern name="book-validation">
        <sch:rule context="book">
            <sch:assert test=".[child::node()[attribute::author]]">
                Invalid book
            </sch:assert>
            
            <sch:report test=".[attribute::author]">
                Valid book
            </sch:report>
        </sch:rule>
    </sch:pattern>
</sch:schema>

THANK YOU..!

Schematron

By Hasini Thamarasa

Schematron

Validating xml documents with rule based approch

  • 664