SlideShare uma empresa Scribd logo
1 de 32
Business Rules Validation
  in the SOA Suite with
       Schematron
PROGRAM
• XML, XSD, X-Path, XSLT

• XML (Business Rule) Validation

• Validation Gap: Schematron

• Examples

• Schematron in the SOA Suite

• Business Rules Case

• Discussion
XML
XML: eXtensible Markup Language

Store almost any kind of data in a structured form
that applications running on any platform can
easily import and process and is human
readable.

XML became the underlying standard for many
new Software standards:
  • Web: XHTML, RSS, Atom, XMPP (chat), AJAX
  • Web Services: WSDL, SOAP (Simple Object
    Access Protocol)
  • Documents: ODF (Open Document Format), MS
    Office OOXML (docx), Apple iWork
  • Etc., etc
XML EXAMPLE
<?xml version="1.0"?>
<dining-room>
  <manufacturer>The WoodShop</manufacturer>
  <table type="round" wood="maple">
    <price>$199.99</price>
  </table>
  <chair wood="maple">
    <quantity>6</quantity>
    <price>$39.99</price>
  </chair>
</dining-room>
XSD
XML Schema:
• Define structure of xml including data type of elements
  and contstraints

• Schema is also in XML format
   So there is a XML schema that defines an XML
  schema

• Can be seen as the “ERD” or “DB Design” for XML
XSD EXAMPLE
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://amis.nl/schematrondemo/common"
            targetNamespace="http://amis.nl/schematrondemo/common"
            elementFormDefault="qualified">
  <xsd:element name="Employees" type="tEmployees"/>
  <xsd:complexType name="tEmployees">
    <xsd:sequence>
      <xsd:element name="Employee" type="tEmployee"
                   minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="tEmployee">
    <xsd:sequence>
      <xsd:element name="Name" type="xsd:string"/>
      <xsd:element name="Salary" type="xsd:decimal"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:long" use="required"/>
    <xsd:attribute name="manager_id" type="xsd:long" use="optional"/>
  </xsd:complexType>
</xsd:schema>
XPATH

XML Path Language (XPath):
  • Is primarily used to address the nodes of an
    XML document modeled as a tree of nodes
  • Is named after its use of a path notation for
    navigating through the hierarchical structure
    of an XML document
  • Uses a compact, non-XML syntax to form
    expressions for use in Uniform Resource
    Identifier (URI) and XML attribute values
  • Fully supports XML Namespaces
  • Is designed to be used by XML applications
    and XSLT (and XQuery)
XPATH EXAMPLES




//price                              2 element nodes
/*/*/@wood                           2 attribute nodes
//@wood/..                           2 nodes (table and chair)
/dining-room/*[price > 100]/@wood  1 attribute node
//price[1]/text()                    2 text values! (both price are first)
(//price)[1]/text()              1 text value (first from result collection)
XML STYLESHEET (XSLT/XSL)
XSLT processing takes an XML source document and an
XSLT stylesheet, and produces an output document
The XSLT stylesheet:
    • Is an XML document itself
    • Contains rules that map patterns in the input to
      static XML to send into the output
    • Uses XPath expressions to get data from the XML
      source
    • Can contain XSLT logic (if, choose) and operators
      (for-each) to process the XML source
The output document is typically another XML
document, but XSLT can be used to create other plain-
text documents as well.
XSLT EXAMPLE *
XML (BUSINESS RULE) VALIDATION

Three types of XML Validation

• On data / element itself:
    Data type & Constraints

• XML Structure:
    Element names & Child/Parent Constraints

• Between data elements:
    Business Rules
XML (BUSINESS RULE) VALIDATION
Three types of XML Validation

•   On data / element itself:
       Data type & Constraints
                  XSD

•   XML Structure:
      Element names & Child/Parent Constraints
                 XSD partially! (no conditional)

•   Between data elements:
       Business Rules
                 ??
SCHEMATRON
• Used for validating an XML Document

• Validation of Business Rules

• Validation of conditional structure

• Rules are defined in Schematron format which
  is also XML

• Is built on XPath expressions

• Is an ISO/IEC Standard

• Basically is a double XSTL transformation
SCHEMATRON
Usage:

• Define your Business Rules in an XML
  document in a fixed format and structure
  (Schematron) with the usage of XPath
  expressions

• Transform your Business Rules XML using the
  Schematron XSLT to create your Business
  Rules XSLT.

• Use your Business Rules XSLT to validate your
  XML data (Transformation). Output are the
  errors, so no output means the data is valid.
SCHEMATRON
• Double XSLT transformation:
   • 1. Rules.xml with Schematron.xslt =>
     Rules.xslt
   • 2. Data.xml with Rules.xslt => Result
SCHEMATRON FILE
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">

 <pattern name="patternName">
   <rule context="x-path">
     <assert test="x-path condition">Error message</assert>
     <report test="x-path condition">Error message</report>
     ...
   </rule>
 </pattern>

 <pattern name="patternName">
 ...

</schema>
SCHEMATRON EXAMPLE 1
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron" >
  <pattern name="Number of characters in an abbreviation">
    <rule context="Afdeling">
      <report test="string-length(@afk) &lt; 2">There are not enough
   letters in the abbreviation</report>

      <report test="string-length(@afk) > 3">There are too much
   letters in the abbreviation</report>
    </rule>
  </pattern>
</schema>
SCHEMATRON EXAMPLE 2
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron" >
  <pattern name="Sum equals 100%.">
    <rule context="Total">
      <assert test="sum(//Percent) = 100">Sum percentage is not
   100%.</assert>
    </rule>
  </pattern>
</schema>
SCHEMATRON IN THE SOA SUITE
• Default filename extension “sch”
• No report, so only assert tag!  not(report)
• Define namespace prefixes with uri tag:
   <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" />

• Implemented in Mediator:




• „Feature‟: Generate HTTP error (e.g. return error with FireForget)
BUSINESS RULES CASE

Company HRM XML file company containing departments
containing employees:
• An employee may not be the manager of himself.
• All normal employees (so not a manager) must have a
  manager.
• There is only one manager without a manager
  (only one president).
• All employees should have less salary than any
  manager
  (manager = employee in department “Managers”).
• The relation manager and employee is a valid one, so
  the manager of an employee must exist.
CASE EXAMPLE DATA
<Company><Department name="Ground Two" abbr="GR1">...</Department>
  <Department name="Ground Two" abbr="GR2">
     <Employees>
        <Employee id="13" manager_id="20">
           <Name>P. Pietersen</Name>
           <Salary>1550</Salary>
        </Employee>
        <Employee id="14" manager_id="20">
           <Name>S. Smit</Name>
           <Salary>1600</Salary>
        </Employee>
     </Employees>
  </Department>
  <Department name="Managers" abbr="MAN">
     <Employees>
        <Employee id="15">
           <Name>M.A. Nager</Name>
           <Salary>1700</Salary>
        </Employee>
        <Employee id="20" manager_id="25">
           <Name>L.E. Ader</Name>
           <Salary>1600</Salary>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     An employee may not be the manager of himself.


<pattern name="Employee may not be the manager of himself">
  <rule context="//com:Employee[@manager_id]">
    <assert test="@manager_id != @id">Employee may not manage himself</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     All normal employees (so not a manager) must
     have a manager.

<pattern name="All normal employees have a manager">
  <rule context=
"//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
    <assert test="@manager_id">Employee must have a manager</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     There is only one manager without a manager
     (only one president).

<pattern name="Only one manager without manager, mr president">
  <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees">
    <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be
only one president</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     All employees should have less salary than any
     manager
     (manager = employee in department “Managers”).
<pattern name="Managers earn more than normal employees">
  <rule
context="//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
    <assert test="com:Salary &lt;
min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">
Employee earns too much</assert>
  </rule>
</pattern>
SCHEMATRON BUSINESS RULE
            IMPLEMENTATION
     The relation manager and employee is a valid
     one, so the manager of an employee must exist.

<pattern name="Manager does not exist">
  <rule context="//com:Employee[@manager_id]">
    <assert test=
"//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees/com:Employee[@id=c
urrent()/@manager_id]">No valid manager</assert>
  </rule>
</pattern>
TOTAL SCHEMATRON BUSINESS RULE
                IMPLEMENTATION
<?xml version="1.0" encoding="UTF-8" ?>
<schema xmlns="http://www.ascc.net/xml/schematron">
  <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" />
  <ns uri="http://amis.nl/schematrondemo/common" prefix="com" />
  <pattern name="Managers earn more than normal employees">
    <rule context= "//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
      <assert test="com:Salary &lt;
min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">Employee
earns too much: <value-of select="com:Salary"/></assert>
    </rule>
  </pattern>
  <pattern name="Employee may not be the manager of himself">
    <rule context="//com:Employee[@manager_id]">
      <assert test="@manager_id != @id">Employee may not manage himself</assert>
    </rule>
  </pattern>
  <pattern name="All normal employees have a manager">
    <rule context=
"//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee">
      <assert test="@manager_id">Employee must have a manager</assert>
    </rule>
  </pattern>
  <pattern name="Only one manager without manager, the president">
    <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees">
      <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one
president</assert>
...
DEMO
PERFORMANCE

When there are
1. a lot (hundreds) of Schematron rules and/or
2. your input data (payload) is huge
performance problems can arise.
PERFORMANCE

1. A lot (hundreds) of Schematron rules

This problem is the easiest to handle:
Split the Schematron file up in more files and
serialize them with Mediators.
Place the Schematron rules which fail most in the
first Mediator and the ones which fail least in the last
Mediator.
PERFORMANCE

2. Huge input data (payload)

This problem is quite tricky. Not only for Schematron
validation, but the SOA Suite in common!
Advise for Schematron validation is to split up the
payload (BPEL / OSB) in multiple chunks.
This can be a „vertical split‟, so divide at certain
elements.
But also an „horizontal‟ split, so ommit data which is
not necessary for the (chunk of) Schematron
validation rules.
Even a combination is possible!
With a split-join in the OSB or in BPEL with parallel
processing the output can be merged.
DISCUSSION
                Statement:
“No Business Rules in the Middleware”

Mais conteúdo relacionado

Semelhante a XML Business Rules Validation with Schematron

Semelhante a XML Business Rules Validation with Schematron (20)

Xml part5
Xml part5Xml part5
Xml part5
 
Xml part1
Xml part1  Xml part1
Xml part1
 
Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De Htlm
 
Xsd
XsdXsd
Xsd
 
Xsd
XsdXsd
Xsd
 
Service Oriented Architecture - Unit II
Service Oriented Architecture - Unit IIService Oriented Architecture - Unit II
Service Oriented Architecture - Unit II
 
DB2 Native XML
DB2 Native XMLDB2 Native XML
DB2 Native XML
 
Xml and databases
Xml and databasesXml and databases
Xml and databases
 
Spring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring BatchSpring Web Service, Spring Integration and Spring Batch
Spring Web Service, Spring Integration and Spring Batch
 
Zero One Or Many Namespaces
Zero One Or Many NamespacesZero One Or Many Namespaces
Zero One Or Many Namespaces
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Xml 2
Xml  2 Xml  2
Xml 2
 
[Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment][Km] [wp] [3] [assignment]
[Km] [wp] [3] [assignment]
 
Android de la A a la Z XML Ulises Gonzalez
Android de la A a la Z  XML Ulises GonzalezAndroid de la A a la Z  XML Ulises Gonzalez
Android de la A a la Z XML Ulises Gonzalez
 
eXtensible Markup Language (XML)
eXtensible Markup Language (XML)eXtensible Markup Language (XML)
eXtensible Markup Language (XML)
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
 
Xml
XmlXml
Xml
 
Transforming xml with XSLT
Transforming  xml with XSLTTransforming  xml with XSLT
Transforming xml with XSLT
 
Soa suite doc
Soa suite docSoa suite doc
Soa suite doc
 

Último

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

XML Business Rules Validation with Schematron

  • 1. Business Rules Validation in the SOA Suite with Schematron
  • 2. PROGRAM • XML, XSD, X-Path, XSLT • XML (Business Rule) Validation • Validation Gap: Schematron • Examples • Schematron in the SOA Suite • Business Rules Case • Discussion
  • 3. XML XML: eXtensible Markup Language Store almost any kind of data in a structured form that applications running on any platform can easily import and process and is human readable. XML became the underlying standard for many new Software standards: • Web: XHTML, RSS, Atom, XMPP (chat), AJAX • Web Services: WSDL, SOAP (Simple Object Access Protocol) • Documents: ODF (Open Document Format), MS Office OOXML (docx), Apple iWork • Etc., etc
  • 4. XML EXAMPLE <?xml version="1.0"?> <dining-room> <manufacturer>The WoodShop</manufacturer> <table type="round" wood="maple"> <price>$199.99</price> </table> <chair wood="maple"> <quantity>6</quantity> <price>$39.99</price> </chair> </dining-room>
  • 5. XSD XML Schema: • Define structure of xml including data type of elements and contstraints • Schema is also in XML format  So there is a XML schema that defines an XML schema • Can be seen as the “ERD” or “DB Design” for XML
  • 6. XSD EXAMPLE <?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://amis.nl/schematrondemo/common" targetNamespace="http://amis.nl/schematrondemo/common" elementFormDefault="qualified"> <xsd:element name="Employees" type="tEmployees"/> <xsd:complexType name="tEmployees"> <xsd:sequence> <xsd:element name="Employee" type="tEmployee" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="tEmployee"> <xsd:sequence> <xsd:element name="Name" type="xsd:string"/> <xsd:element name="Salary" type="xsd:decimal"/> </xsd:sequence> <xsd:attribute name="id" type="xsd:long" use="required"/> <xsd:attribute name="manager_id" type="xsd:long" use="optional"/> </xsd:complexType> </xsd:schema>
  • 7. XPATH XML Path Language (XPath): • Is primarily used to address the nodes of an XML document modeled as a tree of nodes • Is named after its use of a path notation for navigating through the hierarchical structure of an XML document • Uses a compact, non-XML syntax to form expressions for use in Uniform Resource Identifier (URI) and XML attribute values • Fully supports XML Namespaces • Is designed to be used by XML applications and XSLT (and XQuery)
  • 8. XPATH EXAMPLES //price  2 element nodes /*/*/@wood  2 attribute nodes //@wood/..  2 nodes (table and chair) /dining-room/*[price > 100]/@wood  1 attribute node //price[1]/text()  2 text values! (both price are first) (//price)[1]/text()  1 text value (first from result collection)
  • 9. XML STYLESHEET (XSLT/XSL) XSLT processing takes an XML source document and an XSLT stylesheet, and produces an output document The XSLT stylesheet: • Is an XML document itself • Contains rules that map patterns in the input to static XML to send into the output • Uses XPath expressions to get data from the XML source • Can contain XSLT logic (if, choose) and operators (for-each) to process the XML source The output document is typically another XML document, but XSLT can be used to create other plain- text documents as well.
  • 11. XML (BUSINESS RULE) VALIDATION Three types of XML Validation • On data / element itself: Data type & Constraints • XML Structure: Element names & Child/Parent Constraints • Between data elements: Business Rules
  • 12. XML (BUSINESS RULE) VALIDATION Three types of XML Validation • On data / element itself: Data type & Constraints  XSD • XML Structure: Element names & Child/Parent Constraints  XSD partially! (no conditional) • Between data elements: Business Rules  ??
  • 13. SCHEMATRON • Used for validating an XML Document • Validation of Business Rules • Validation of conditional structure • Rules are defined in Schematron format which is also XML • Is built on XPath expressions • Is an ISO/IEC Standard • Basically is a double XSTL transformation
  • 14. SCHEMATRON Usage: • Define your Business Rules in an XML document in a fixed format and structure (Schematron) with the usage of XPath expressions • Transform your Business Rules XML using the Schematron XSLT to create your Business Rules XSLT. • Use your Business Rules XSLT to validate your XML data (Transformation). Output are the errors, so no output means the data is valid.
  • 15. SCHEMATRON • Double XSLT transformation: • 1. Rules.xml with Schematron.xslt => Rules.xslt • 2. Data.xml with Rules.xslt => Result
  • 16. SCHEMATRON FILE <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron"> <pattern name="patternName"> <rule context="x-path"> <assert test="x-path condition">Error message</assert> <report test="x-path condition">Error message</report> ... </rule> </pattern> <pattern name="patternName"> ... </schema>
  • 17. SCHEMATRON EXAMPLE 1 <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron" > <pattern name="Number of characters in an abbreviation"> <rule context="Afdeling"> <report test="string-length(@afk) &lt; 2">There are not enough letters in the abbreviation</report> <report test="string-length(@afk) > 3">There are too much letters in the abbreviation</report> </rule> </pattern> </schema>
  • 18. SCHEMATRON EXAMPLE 2 <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron" > <pattern name="Sum equals 100%."> <rule context="Total"> <assert test="sum(//Percent) = 100">Sum percentage is not 100%.</assert> </rule> </pattern> </schema>
  • 19. SCHEMATRON IN THE SOA SUITE • Default filename extension “sch” • No report, so only assert tag!  not(report) • Define namespace prefixes with uri tag: <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" /> • Implemented in Mediator: • „Feature‟: Generate HTTP error (e.g. return error with FireForget)
  • 20. BUSINESS RULES CASE Company HRM XML file company containing departments containing employees: • An employee may not be the manager of himself. • All normal employees (so not a manager) must have a manager. • There is only one manager without a manager (only one president). • All employees should have less salary than any manager (manager = employee in department “Managers”). • The relation manager and employee is a valid one, so the manager of an employee must exist.
  • 21. CASE EXAMPLE DATA <Company><Department name="Ground Two" abbr="GR1">...</Department> <Department name="Ground Two" abbr="GR2"> <Employees> <Employee id="13" manager_id="20"> <Name>P. Pietersen</Name> <Salary>1550</Salary> </Employee> <Employee id="14" manager_id="20"> <Name>S. Smit</Name> <Salary>1600</Salary> </Employee> </Employees> </Department> <Department name="Managers" abbr="MAN"> <Employees> <Employee id="15"> <Name>M.A. Nager</Name> <Salary>1700</Salary> </Employee> <Employee id="20" manager_id="25"> <Name>L.E. Ader</Name> <Salary>1600</Salary>
  • 22. SCHEMATRON BUSINESS RULE IMPLEMENTATION An employee may not be the manager of himself. <pattern name="Employee may not be the manager of himself"> <rule context="//com:Employee[@manager_id]"> <assert test="@manager_id != @id">Employee may not manage himself</assert> </rule> </pattern>
  • 23. SCHEMATRON BUSINESS RULE IMPLEMENTATION All normal employees (so not a manager) must have a manager. <pattern name="All normal employees have a manager"> <rule context= "//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="@manager_id">Employee must have a manager</assert> </rule> </pattern>
  • 24. SCHEMATRON BUSINESS RULE IMPLEMENTATION There is only one manager without a manager (only one president). <pattern name="Only one manager without manager, mr president"> <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees"> <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one president</assert> </rule> </pattern>
  • 25. SCHEMATRON BUSINESS RULE IMPLEMENTATION All employees should have less salary than any manager (manager = employee in department “Managers”). <pattern name="Managers earn more than normal employees"> <rule context="//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="com:Salary &lt; min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)"> Employee earns too much</assert> </rule> </pattern>
  • 26. SCHEMATRON BUSINESS RULE IMPLEMENTATION The relation manager and employee is a valid one, so the manager of an employee must exist. <pattern name="Manager does not exist"> <rule context="//com:Employee[@manager_id]"> <assert test= "//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees/com:Employee[@id=c urrent()/@manager_id]">No valid manager</assert> </rule> </pattern>
  • 27. TOTAL SCHEMATRON BUSINESS RULE IMPLEMENTATION <?xml version="1.0" encoding="UTF-8" ?> <schema xmlns="http://www.ascc.net/xml/schematron"> <ns uri="http://amis.nl/schematrondemo/company" prefix="cmp" /> <ns uri="http://amis.nl/schematrondemo/common" prefix="com" /> <pattern name="Managers earn more than normal employees"> <rule context= "//cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="com:Salary &lt; min(//cmp:Department[@name='Managers']/cmp:Employees/com:Employee/com:Salary)">Employee earns too much: <value-of select="com:Salary"/></assert> </rule> </pattern> <pattern name="Employee may not be the manager of himself"> <rule context="//com:Employee[@manager_id]"> <assert test="@manager_id != @id">Employee may not manage himself</assert> </rule> </pattern> <pattern name="All normal employees have a manager"> <rule context= "//cmp:Company/cmp:Department[@name!='Managers']/cmp:Employees/com:Employee"> <assert test="@manager_id">Employee must have a manager</assert> </rule> </pattern> <pattern name="Only one manager without manager, the president"> <rule context="//cmp:Company/cmp:Department[@name='Managers']/cmp:Employees"> <assert test="count(com:Employee[not(@manager_id)]) = 1">There should be only one president</assert> ...
  • 28. DEMO
  • 29. PERFORMANCE When there are 1. a lot (hundreds) of Schematron rules and/or 2. your input data (payload) is huge performance problems can arise.
  • 30. PERFORMANCE 1. A lot (hundreds) of Schematron rules This problem is the easiest to handle: Split the Schematron file up in more files and serialize them with Mediators. Place the Schematron rules which fail most in the first Mediator and the ones which fail least in the last Mediator.
  • 31. PERFORMANCE 2. Huge input data (payload) This problem is quite tricky. Not only for Schematron validation, but the SOA Suite in common! Advise for Schematron validation is to split up the payload (BPEL / OSB) in multiple chunks. This can be a „vertical split‟, so divide at certain elements. But also an „horizontal‟ split, so ommit data which is not necessary for the (chunk of) Schematron validation rules. Even a combination is possible! With a split-join in the OSB or in BPEL with parallel processing the output can be merged.
  • 32. DISCUSSION Statement: “No Business Rules in the Middleware”