SlideShare a Scribd company logo
1 of 9
Download to read offline
Extending XML Schemas
Table of Contents
               Issue
               Tutorial
               Introduction
               Three Options for Extending XML Schemas
                         Supplement with Another Schema Language
                         Write Code to Express Additional Constraints
                         Express Additional Constraints with an XSLT/XPath Stylesheet
               Advantages/Disadvantages of the Three Options
                         Advantages/Disadvantages of Supplementing with Another Schema
                         Language
                         Advantages/Disadvantages of Writing Code to Express Additional
                         Constraints
                         Advantages/Disadvantages of Expressing Additional Constraints with
                         an XSLT/XPath Stylesheet
Issue
What is Best Practice for checking instance documents for constraints that are not expressable
by XML Schemas?

Introduction
XML Schemas is very powerful. However, it is not “all powerful”. There are many constraints
which cannot be expressed with XML Schemas. Here are some examples:
– Ensure that the value of the aircraft <Elevation> element is greater than the value of the
  obstacle <Height> element.
– Ensure that:
  – if the value of the attribute, mode, is “water” then the value of the element <Transportation>
     is either airplane or hot-air balloon.
  – if the value of the attribute, mode, is “air” then <Transportation> is either boat or hovercraft.
  – if the value of the attribute, mode, is “ground” then <Transportation> is either car or bicycle.
– Ensure that the value of <PaymentReceived> is equal to the value of <PaymentDue>, where
  these elements are in separate documents!
To check all these constraints we will need to supplement XML Schemas with another tool.




                                                 75
Example. Consider this simple instance document:


  <?xml version=quot;1.0quot;?>
  <Demo xmlns=quot;http://www.demo.orgquot;
        xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
        xsi:schemaLocation=quot;http://www.demo.org demo.xsdquot;>
     <A>10</A>
     <B>20</B>
  </Demo>

With XML Schemas we can check the following constraints:
• the Demo (root) element contains a sequence of elements, A followed by B
• the A element contains an integer
• the B element contains an integer
In fact, here’s an XML Schema which implements these constraints:



   <?xml version=quot;1.0quot;?>
   <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
        targetNamespace=quot;http://www.demo.orgquot;
        xmlns=quot;http://www.demo.orgquot;
       elementFormDefault=quot;qualifiedquot;>
     <xsd:element name=quot;Demoquot;>
       <xsd:complexType>
           <xsd:sequence>
             <xsd:element name=quot;Aquot; type=quot;xsd:integerquot;/>
             <xsd:element name=quot;Bquot; type=quot;xsd:integerquot;/>
           </xsd:sequence>
        </xsd:complexType>
     </xsd:element>
   </xsd:schema>




                                             76
XML Schemas does not give us the capability to express the following constraint:
               the value of A must be greater than the value of B

So what do we do to check this constraint? (Interestingly, for the above instance document, the
XML Schema that is shown would accept it as valid, whereas, in fact it is not since the value of A
is less than the value of B. We need something else to check this constraint.) There are three
options.

Three Options for Extending XML Schemas
(1) Supplement with Another Schema Language
There are many other schema languages besides XML Schemas:
            – Schematron
            – TREX
            – RELAX
            – SOX
            – XDR
            – HOOK
            – DSD
            – Assertion Grammars
            – xlinkit

Thus, the first option is to use one (or more) of these schema languages to express the additional
constraints. Let’s look at one of these languages - Schematron.

Using Schematron you embed the additional constraints (as “assertions”) within the schema
document (within <appinfo> elements). A Schematron engine will then extract the assertions and
validate the instance document against the assertions.




        XML
                                            Schematron                  Valid/invalid
       Schema          Extract assertions
                       from <appinfo>
                       elements




                                               XML
                                               Data




                                                77
Thus, here’s the architecture for determining if your data meets all constraints:



                                           valid
                     Schematron



   XML                                 Your XML            Now you know your XML data is valid!
  Schema                                 data


                     Schema                valid
                     Validator



With Schematron
– state a constraint using an <assert> element
– a <rule> is comprised of one or more <assert> elements
– a <pattern> is comprised of one or more <rule> elements.



                         <pattern>
                           <rule>
                              <assert> … </assert>
                              <assert> … </assert>
                           </rule>
                         </pattern>

The <pattern> element is embedded within an XML Schema <appinfo> element.




                                                   78
Here’s an example of an assertion:


  <assert test=quot;d:A &gt; d:Bquot;>A should be greater than B</assert>

                    XPath expression         Text description of the constraint

In the <assert> element you express a constraint using an XPath expression. Additionally, you
state the constraint in natural language. The later helps make the schemas self-documenting.

The <rule> element is used to specify the context for the <assert> elements.

    <rule context=“d:Demo”>
      <assert test=“d:A &gt; d:B”>A should be greater than B</assert>
    </rule>

This is read as: “Within the context of the Demo element we assert that the A element should be
greater than the B element.”

You can associate an <assert> with a <diagnostic> element. The <diagnostic> element is used for
printing error messages when the XML data fails the assertion. The <diagnostic> element is
embedded within a <diagnostics> element, which immediately follows the <pattern> element.


       <pattern name=“Check A greater than B”>
           <rule context=“d:Demo”>
               <assert test=“d:A &gt; d:B” diagnostics=“lessThan”>
                  A should be greater than B
               </assert>
           </rule>
       </pattern>
       <diagnostics>
           <diagnostic id=“lessThan”>
               Error! A is less than B
               A = <value-of select=“d:A”/>
               B = <value-of select=“d:B”/>
           </diagnostic>
       </diagnostics>

                                               79
To identify the schematron elements, they must be namespace-qualified with sch:.

Here’s what demo.xsd looks like after enhancing it with the Schematron elements: (next page)

The schema document shown earlier is enhanced with Schematron directives:



    <?xml version=quot;1.0quot;?>
    <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
        targetNamespace=quot;http://www.demo.orgquot;
        xmlns=quot;http://www.demo.orgquot;
        xmlns:sch=quot;http://www.ascc.net/xml/Schematron”
        elementFormDefault=quot;qualifiedquot;>
      <xsd:annotation>
        <xsd:appinfo>
           <sch:title>Schematron validation</sch:title>
           <sch:ns prefix=quot;dquot; uri=quot;http://www.demo.orgquot;/>
        </xsd:appinfo>
      </xsd:annotation>
      <xsd:element name=quot;Demoquot;>
        <xsd:annotation>
           <xsd:appinfo>
             <sch:pattern name=quot;Check A greater than Bquot;>
               <sch:rule context=quot;d:Demoquot;>
                  <sch:assert test=quot;d:A &gt; d:Bquot; diagnostics=quot;lessThanquot;>A should be greater than B</sch:assert>
               </sch:rule>
             </sch:pattern>
             <sch:diagnostics>
                <sch:diagnostic id=quot;lessThanquot;>
                  Error! A is less than B. A = <sch:value-of select=quot;d:Aquot;/> B = <sch:value-of select=quot;d:Bquot;/>
               </sch:diagnostic>
             </sch:diagnostics>
           </xsd:appinfo>
        </xsd:annotation>
        <xsd:complexType>
           <xsd:sequence>
             <xsd:element name=quot;Aquot; type=quot;xsd:integerquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
             <xsd:element name=quot;Bquot; type=quot;xsd:integerquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
           </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>




Schematron will extract the directives out of the schema document to create a Schematron
schema. Schematron will then validate the instance document against the Schematron schema.

The key points to note about using Schematron are:
                The additional constraints are embedded in <appinfo> elements within the XML
                Schema document
                The constraints are expressed using <assert> elements



                                                        80
(2) Write Code to Express Additional Constraints
The second option is to write some Java, Perl, C++, etc code to check additional constraints.

(3) Express Additional Constraints with an XSLT/XPath Stylesheet
The third option is to write a stylesheet to check the constraints.



                  XML
                 Schema


                               Schema                 valid
                               Validator
                                                              Now you know your XML data is valid!
        Your XML
          data
                                 XSL                 valid
                               Processor

         XSLT Stylesheet
          containing code
        to check additional
            constraints


For example, the following stylesheet checks instance documents to see if the contents of the A
element is greater than the contents of the B element:


                     <?xml version=quot;1.0quot;?>
                     <xsl:stylesheet xmlns:xsl=quot;http://www.w3.org/1999/XSL/Transformquot;
                               xmlns:d=quot;http://www.demo.orgquot;
                               version=quot;1.0quot;>

                       <xsl:output method=quot;textquot;/>

                       <xsl:template match=quot;/quot;>
                          <xsl:if test=quot;/d:Demo/d:A &lt; /d:Demo/d:Bquot;>
                             <xsl:text>Error! A is less than B</xsl:text>
                             <xsl:text>&#xD;&#xA;</xsl:text> <!-- carriage return -->
                             <xsl:text>A = </xsl:text><xsl:value-of select=quot;/d:Demo/d:Aquot;/>
                             <xsl:text>&#xD;&#xA;</xsl:text> <!-- carriage return -->
                             <xsl:text>B = </xsl:text><xsl:value-of select=quot;/d:Demo/d:Bquot;/>
                          </xsl:if>
                          <xsl:if test=quot;/d:Demo/d:A &gt;= /d:Demo/d:Bquot;>
                             <xsl:text>Instance document is valid</xsl:text>
                          </xsl:if>
                       </xsl:template>
                     </xsl:stylesheet>



                                                      81
Upon running this stylesheet on the above XML data the following output is generated:

            Error! A is less than B. A = 10, B = 20

This is exactly what is desired. Thus, the methodology for this third option is:
– check as many constraints as you can using XML Schemas
– for all other constraints write a stylesheet to do the checking
If both the schema validator and the XSL processor generate a positive output then you know that
your instance document is valid. This combination of XML Schemas plus stylesheets provides
for a powerful constraint checking mechanism.

Advantages/Disadvantages of the Three Options
Advantages
               Collocated Constraints: Above we saw how Schematron can be used to express
               additional constraints. We saw that you embed the Schematron directives within
               the XML Schema document. There is something very appealing about having all
               the constraints expressed within one document rather than being dispersed over
               multiple documents. [This ability to collocate constraints within the schema
               document is a feature of Schematron. The other schema languages do not have
               this capability.]
               Simplicity: Many of the schema languages were created in reaction to the com-
               plexity and limitations of XML Schemas. Consequently, most of them are rela-
               tively simple to learn and use.

Disadvantages
             Multiple Schema Languages may be Required: Each schema language has its
             own capabilities and limitations. Multiple schema languages may be required to
             express all the additional constraints. For example, while Schematron is very
             powerful it is not able to express all constraints (for an example, see the ISBN
             simpleType definition on http://www.xfront.com). Also, Schematron forces you to
             go through many contortions to express your assertion. This is due to the fact that
             it does not have loops and variables.
               Yet Another Vocabulary (YAV): There are many schema languages, each with its
               own vocabulary and semantics. How do you find a schema language with the
               capability to express your problem’s additional constraints? You have to take the
               time to learn each of the schema languages. Hopefully, you will find one that
               supports expression of your constraints. Although relatively easy to learn and use,
               it still takes time to learn a new vocabulary and semantics.




                                                 82
Questionable Long Term Support: In most cases the schema languages listed
              above were created by a single author. These authors are busy, very bright people.
              Someday their interests will move to something else. At that time you may be left
              with a product which is no longer supported. [Editor’s Note: Schematron is
              basically a few XSLT/XPath stylesheets. Consequently, Schematron will be
              supported as long as there are XSL processors. Also, the author of RELAX has
              publically promised to support RELAX for the next five years.]

(2) Write Code to Express Additional Constraints
Advantages
              Full Power of a Programming Language: The advantage of this option is that
              with a single programming language you can express all the additional con-
              straints.

Disadvantages
             Not Leveraging other XML Technologies: There are other XML technologies
             that could be used to express the additional constraints in a declarative manner,
             without going through the compiling, linking, executing effort.

(3) Express Additional Constraints with an XSLT/XPath Stylesheet
Advantages
              Application Specific Constraint Checking: Each application can create its own
              stylesheet to check constraints that are unique to the application. We can enhance
              the schema without touching it!
              Core Technology: XSLT/XPath is a “core technology” which is well supported,
              well understood, and with lots of material written on it.
              Expressive Power: XSLT/XPath is a very powerful language. Most, if not every,
              constraint that you might ever need to express can be expressed using XSLT/
              XPath. Thus you don’t have to learn multiple schema languages to express your
              additional constraints
              Long Term Support: XSLT/XPath is well supported, and will be around for a
              long time.

Disadvantages
             Separate Documents: With this approach you will write your XML Schema
             document, then you will write a separate XSLT/XPath document to express
             additional constraints. Keeping the two documents in synch needs to be carefully
             managed.




                                               83

More Related Content

What's hot

2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표
Sunjoo Park
 
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
phanleson
 
IE for Semi-structured Document: Supervised Approach
IE for Semi-structured Document: Supervised ApproachIE for Semi-structured Document: Supervised Approach
IE for Semi-structured Document: Supervised Approach
butest
 

What's hot (15)

Web Designing
Web DesigningWeb Designing
Web Designing
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
 
JAVASCRIPT - LinkedIn
JAVASCRIPT - LinkedInJAVASCRIPT - LinkedIn
JAVASCRIPT - LinkedIn
 
2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표
 
Quick Referance to WML
Quick Referance to WMLQuick Referance to WML
Quick Referance to WML
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...Xml For Dummies   Chapter 12 Handling Transformations With Xsl it-slideshares...
Xml For Dummies Chapter 12 Handling Transformations With Xsl it-slideshares...
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changes
 
A quick guide to Css and java script
A quick guide to Css and  java scriptA quick guide to Css and  java script
A quick guide to Css and java script
 
IE for Semi-structured Document: Supervised Approach
IE for Semi-structured Document: Supervised ApproachIE for Semi-structured Document: Supervised Approach
IE for Semi-structured Document: Supervised Approach
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1
 
DIWE - Coding HTML for Basic Web Designing
DIWE - Coding HTML for Basic Web DesigningDIWE - Coding HTML for Basic Web Designing
DIWE - Coding HTML for Basic Web Designing
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To Hibernate
 
XML
XMLXML
XML
 
Xml
XmlXml
Xml
 

Similar to Extending Schemas

Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wpSql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
Klaudiia Jacome
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
Adhoura Academy
 

Similar to Extending Schemas (20)

Xml Schema
Xml SchemaXml Schema
Xml Schema
 
XSD
XSDXSD
XSD
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Schematron and Other Useful Tools
Schematron and Other Useful ToolsSchematron and Other Useful Tools
Schematron and Other Useful Tools
 
Java scripts
Java scriptsJava scripts
Java scripts
 
Expanding a tree node
Expanding a tree nodeExpanding a tree node
Expanding a tree node
 
Xml Demystified
Xml DemystifiedXml Demystified
Xml Demystified
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
AdvancedXPath
AdvancedXPathAdvancedXPath
AdvancedXPath
 
Mazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml ToolsMazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml Tools
 
Introduction To Xml
Introduction To XmlIntroduction To Xml
Introduction To Xml
 
XML Training Presentation
XML Training PresentationXML Training Presentation
XML Training Presentation
 
Xml
XmlXml
Xml
 
Sql server 2008 r2 xml wp
Sql server 2008 r2 xml wpSql server 2008 r2 xml wp
Sql server 2008 r2 xml wp
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Versioning
VersioningVersioning
Versioning
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Markup Documents
Markup DocumentsMarkup Documents
Markup Documents
 

More from LiquidHub

Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade process
LiquidHub
 
Share point 2013
Share point 2013Share point 2013
Share point 2013
LiquidHub
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovements
LiquidHub
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
LiquidHub
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010
LiquidHub
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share point
LiquidHub
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server Deployment
LiquidHub
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install Databases
LiquidHub
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment Detail
LiquidHub
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup Strategies
LiquidHub
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
LiquidHub
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps
LiquidHub
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007
LiquidHub
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
LiquidHub
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components Refresh
LiquidHub
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
LiquidHub
 

More from LiquidHub (20)

Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade process
 
Share point 2013
Share point 2013Share point 2013
Share point 2013
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovements
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share point
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server Deployment
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install Databases
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment Detail
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup Strategies
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps
 
5060 A 01
5060 A 015060 A 01
5060 A 01
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components Refresh
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Extending Schemas

  • 1. Extending XML Schemas Table of Contents Issue Tutorial Introduction Three Options for Extending XML Schemas Supplement with Another Schema Language Write Code to Express Additional Constraints Express Additional Constraints with an XSLT/XPath Stylesheet Advantages/Disadvantages of the Three Options Advantages/Disadvantages of Supplementing with Another Schema Language Advantages/Disadvantages of Writing Code to Express Additional Constraints Advantages/Disadvantages of Expressing Additional Constraints with an XSLT/XPath Stylesheet Issue What is Best Practice for checking instance documents for constraints that are not expressable by XML Schemas? Introduction XML Schemas is very powerful. However, it is not “all powerful”. There are many constraints which cannot be expressed with XML Schemas. Here are some examples: – Ensure that the value of the aircraft <Elevation> element is greater than the value of the obstacle <Height> element. – Ensure that: – if the value of the attribute, mode, is “water” then the value of the element <Transportation> is either airplane or hot-air balloon. – if the value of the attribute, mode, is “air” then <Transportation> is either boat or hovercraft. – if the value of the attribute, mode, is “ground” then <Transportation> is either car or bicycle. – Ensure that the value of <PaymentReceived> is equal to the value of <PaymentDue>, where these elements are in separate documents! To check all these constraints we will need to supplement XML Schemas with another tool. 75
  • 2. Example. Consider this simple instance document: <?xml version=quot;1.0quot;?> <Demo xmlns=quot;http://www.demo.orgquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation=quot;http://www.demo.org demo.xsdquot;> <A>10</A> <B>20</B> </Demo> With XML Schemas we can check the following constraints: • the Demo (root) element contains a sequence of elements, A followed by B • the A element contains an integer • the B element contains an integer In fact, here’s an XML Schema which implements these constraints: <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.demo.orgquot; xmlns=quot;http://www.demo.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:element name=quot;Demoquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Aquot; type=quot;xsd:integerquot;/> <xsd:element name=quot;Bquot; type=quot;xsd:integerquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> 76
  • 3. XML Schemas does not give us the capability to express the following constraint: the value of A must be greater than the value of B So what do we do to check this constraint? (Interestingly, for the above instance document, the XML Schema that is shown would accept it as valid, whereas, in fact it is not since the value of A is less than the value of B. We need something else to check this constraint.) There are three options. Three Options for Extending XML Schemas (1) Supplement with Another Schema Language There are many other schema languages besides XML Schemas: – Schematron – TREX – RELAX – SOX – XDR – HOOK – DSD – Assertion Grammars – xlinkit Thus, the first option is to use one (or more) of these schema languages to express the additional constraints. Let’s look at one of these languages - Schematron. Using Schematron you embed the additional constraints (as “assertions”) within the schema document (within <appinfo> elements). A Schematron engine will then extract the assertions and validate the instance document against the assertions. XML Schematron Valid/invalid Schema Extract assertions from <appinfo> elements XML Data 77
  • 4. Thus, here’s the architecture for determining if your data meets all constraints: valid Schematron XML Your XML Now you know your XML data is valid! Schema data Schema valid Validator With Schematron – state a constraint using an <assert> element – a <rule> is comprised of one or more <assert> elements – a <pattern> is comprised of one or more <rule> elements. <pattern> <rule> <assert> … </assert> <assert> … </assert> </rule> </pattern> The <pattern> element is embedded within an XML Schema <appinfo> element. 78
  • 5. Here’s an example of an assertion: <assert test=quot;d:A &gt; d:Bquot;>A should be greater than B</assert> XPath expression Text description of the constraint In the <assert> element you express a constraint using an XPath expression. Additionally, you state the constraint in natural language. The later helps make the schemas self-documenting. The <rule> element is used to specify the context for the <assert> elements. <rule context=“d:Demo”> <assert test=“d:A &gt; d:B”>A should be greater than B</assert> </rule> This is read as: “Within the context of the Demo element we assert that the A element should be greater than the B element.” You can associate an <assert> with a <diagnostic> element. The <diagnostic> element is used for printing error messages when the XML data fails the assertion. The <diagnostic> element is embedded within a <diagnostics> element, which immediately follows the <pattern> element. <pattern name=“Check A greater than B”> <rule context=“d:Demo”> <assert test=“d:A &gt; d:B” diagnostics=“lessThan”> A should be greater than B </assert> </rule> </pattern> <diagnostics> <diagnostic id=“lessThan”> Error! A is less than B A = <value-of select=“d:A”/> B = <value-of select=“d:B”/> </diagnostic> </diagnostics> 79
  • 6. To identify the schematron elements, they must be namespace-qualified with sch:. Here’s what demo.xsd looks like after enhancing it with the Schematron elements: (next page) The schema document shown earlier is enhanced with Schematron directives: <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.demo.orgquot; xmlns=quot;http://www.demo.orgquot; xmlns:sch=quot;http://www.ascc.net/xml/Schematron” elementFormDefault=quot;qualifiedquot;> <xsd:annotation> <xsd:appinfo> <sch:title>Schematron validation</sch:title> <sch:ns prefix=quot;dquot; uri=quot;http://www.demo.orgquot;/> </xsd:appinfo> </xsd:annotation> <xsd:element name=quot;Demoquot;> <xsd:annotation> <xsd:appinfo> <sch:pattern name=quot;Check A greater than Bquot;> <sch:rule context=quot;d:Demoquot;> <sch:assert test=quot;d:A &gt; d:Bquot; diagnostics=quot;lessThanquot;>A should be greater than B</sch:assert> </sch:rule> </sch:pattern> <sch:diagnostics> <sch:diagnostic id=quot;lessThanquot;> Error! A is less than B. A = <sch:value-of select=quot;d:Aquot;/> B = <sch:value-of select=quot;d:Bquot;/> </sch:diagnostic> </sch:diagnostics> </xsd:appinfo> </xsd:annotation> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Aquot; type=quot;xsd:integerquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> <xsd:element name=quot;Bquot; type=quot;xsd:integerquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Schematron will extract the directives out of the schema document to create a Schematron schema. Schematron will then validate the instance document against the Schematron schema. The key points to note about using Schematron are: The additional constraints are embedded in <appinfo> elements within the XML Schema document The constraints are expressed using <assert> elements 80
  • 7. (2) Write Code to Express Additional Constraints The second option is to write some Java, Perl, C++, etc code to check additional constraints. (3) Express Additional Constraints with an XSLT/XPath Stylesheet The third option is to write a stylesheet to check the constraints. XML Schema Schema valid Validator Now you know your XML data is valid! Your XML data XSL valid Processor XSLT Stylesheet containing code to check additional constraints For example, the following stylesheet checks instance documents to see if the contents of the A element is greater than the contents of the B element: <?xml version=quot;1.0quot;?> <xsl:stylesheet xmlns:xsl=quot;http://www.w3.org/1999/XSL/Transformquot; xmlns:d=quot;http://www.demo.orgquot; version=quot;1.0quot;> <xsl:output method=quot;textquot;/> <xsl:template match=quot;/quot;> <xsl:if test=quot;/d:Demo/d:A &lt; /d:Demo/d:Bquot;> <xsl:text>Error! A is less than B</xsl:text> <xsl:text>&#xD;&#xA;</xsl:text> <!-- carriage return --> <xsl:text>A = </xsl:text><xsl:value-of select=quot;/d:Demo/d:Aquot;/> <xsl:text>&#xD;&#xA;</xsl:text> <!-- carriage return --> <xsl:text>B = </xsl:text><xsl:value-of select=quot;/d:Demo/d:Bquot;/> </xsl:if> <xsl:if test=quot;/d:Demo/d:A &gt;= /d:Demo/d:Bquot;> <xsl:text>Instance document is valid</xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet> 81
  • 8. Upon running this stylesheet on the above XML data the following output is generated: Error! A is less than B. A = 10, B = 20 This is exactly what is desired. Thus, the methodology for this third option is: – check as many constraints as you can using XML Schemas – for all other constraints write a stylesheet to do the checking If both the schema validator and the XSL processor generate a positive output then you know that your instance document is valid. This combination of XML Schemas plus stylesheets provides for a powerful constraint checking mechanism. Advantages/Disadvantages of the Three Options Advantages Collocated Constraints: Above we saw how Schematron can be used to express additional constraints. We saw that you embed the Schematron directives within the XML Schema document. There is something very appealing about having all the constraints expressed within one document rather than being dispersed over multiple documents. [This ability to collocate constraints within the schema document is a feature of Schematron. The other schema languages do not have this capability.] Simplicity: Many of the schema languages were created in reaction to the com- plexity and limitations of XML Schemas. Consequently, most of them are rela- tively simple to learn and use. Disadvantages Multiple Schema Languages may be Required: Each schema language has its own capabilities and limitations. Multiple schema languages may be required to express all the additional constraints. For example, while Schematron is very powerful it is not able to express all constraints (for an example, see the ISBN simpleType definition on http://www.xfront.com). Also, Schematron forces you to go through many contortions to express your assertion. This is due to the fact that it does not have loops and variables. Yet Another Vocabulary (YAV): There are many schema languages, each with its own vocabulary and semantics. How do you find a schema language with the capability to express your problem’s additional constraints? You have to take the time to learn each of the schema languages. Hopefully, you will find one that supports expression of your constraints. Although relatively easy to learn and use, it still takes time to learn a new vocabulary and semantics. 82
  • 9. Questionable Long Term Support: In most cases the schema languages listed above were created by a single author. These authors are busy, very bright people. Someday their interests will move to something else. At that time you may be left with a product which is no longer supported. [Editor’s Note: Schematron is basically a few XSLT/XPath stylesheets. Consequently, Schematron will be supported as long as there are XSL processors. Also, the author of RELAX has publically promised to support RELAX for the next five years.] (2) Write Code to Express Additional Constraints Advantages Full Power of a Programming Language: The advantage of this option is that with a single programming language you can express all the additional con- straints. Disadvantages Not Leveraging other XML Technologies: There are other XML technologies that could be used to express the additional constraints in a declarative manner, without going through the compiling, linking, executing effort. (3) Express Additional Constraints with an XSLT/XPath Stylesheet Advantages Application Specific Constraint Checking: Each application can create its own stylesheet to check constraints that are unique to the application. We can enhance the schema without touching it! Core Technology: XSLT/XPath is a “core technology” which is well supported, well understood, and with lots of material written on it. Expressive Power: XSLT/XPath is a very powerful language. Most, if not every, constraint that you might ever need to express can be expressed using XSLT/ XPath. Thus you don’t have to learn multiple schema languages to express your additional constraints Long Term Support: XSLT/XPath is well supported, and will be around for a long time. Disadvantages Separate Documents: With this approach you will write your XML Schema document, then you will write a separate XSLT/XPath document to express additional constraints. Keeping the two documents in synch needs to be carefully managed. 83