SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표Sunjoo Park
 
Quick Referance to WML
Quick Referance to WMLQuick Referance to WML
Quick Referance to WMLNitin Saswade
 
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
 
Amber and beyond: Java language changes
Amber and beyond: Java language changesAmber and beyond: Java language changes
Amber and beyond: Java language changesStephen Colebourne
 
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 scriptAVINASH KUMAR
 
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 Approachbutest
 
Web Design Assignment 1
Web Design Assignment 1 Web Design Assignment 1
Web Design Assignment 1 beretta21
 
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 DesigningRasan Samarasinghe
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To HibernateAmit Himani
 

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

Similaire à Extending XML Schemas with Schematron

Similaire à Extending XML Schemas with Schematron (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
 

Plus de LiquidHub

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.0LiquidHub
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade processLiquidHub
 
Share point 2013
Share point 2013Share point 2013
Share point 2013LiquidHub
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovementsLiquidHub
 
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-2LiquidHub
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010LiquidHub
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share pointLiquidHub
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server DeploymentLiquidHub
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install DatabasesLiquidHub
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment DetailLiquidHub
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup StrategiesLiquidHub
 
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 2003LiquidHub
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration StepsLiquidHub
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007LiquidHub
 
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 WalkthroughLiquidHub
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshLiquidHub
 
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 RefreshLiquidHub
 

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

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
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
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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...
 
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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
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
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
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...
 
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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Extending XML Schemas with Schematron

  • 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