SlideShare una empresa de Scribd logo
1 de 58
Descargar para leer sin conexión
How to develop
Syntax and XML Schema

            Ted Leung
    Chairman, ASF XML PMC
Principal, Sauria Associates, LLC
        twl@sauria.com
Thank You

    ASF
n

    Xerces-J-Dev
n

    Xerces-J-User
n
Outline
    Overview
n

    xml.apache.org project
n

    Business / Technical motivation for XML
n
    Schema
    Coverage of Key XML Schema Features
n

    Alternative Schema Languages
n
Apache Software Foundation
    Non-profit foundation
n
        volunteers
    n

    Open Source Software
n

    Apache License
n
        Not viral like GPL
    n

        Commercial Use is fine
    n

    Projects
n
        Web Server
    n

        jakarta.apache.org
    n

             JSP, Servlets, Ant, Struts, Server Frameworks
         n


        xml.apache.org
    n
xml.apache.org
    Part of the Apache Software Foundation
n

    Open Source XML processing
n

    components
        XML Parser [Xerces] (Java, C++, Perl)
    n

        XSLT processor [Xalan] (Java, C++)
    n

        XSL Formatting Objects [FOP]
    n

        SVG [Batik]
    n

        Cocoon
    n

        SOAP [Apache-SOAP / Axis]
    n
Business Motivation
    XML is a language of agreements
n

    We needed a way to specify those
n

    agreements in more detail – raises the
    level of discourse between applications
    We needed a way for machines to be
n

    able to do more with those agreements
Technical Motivation
    Three major needs leading up to XML
n

    Schema
        Strong data typing of element content and
    n

        attributes – push more validation into the
        XML infrastructure
        Integration of namespaces into grammars
    n

        Use of XML syntax to describe the
    n

        grammar
When would you use Schema?
    You have rich data types [typing]
n

    You need open content models
n

    [wildcards]
    You need to combine data from multiple
n

    organzations [namespaces]
    You are mapping from database
n

    [uniqueness]
Example Schema Applications
    SOAP / WSDL
n

    XSLT 2
n

    XForms
n

    Many more to come
n
XML Schema Specification
    W3C Recommendation as of 5/2/2001
n

    Three documents:
n

        XML Schema Part 0: Primer
    n

        XML Schema Part 1: Structures
    n

        XML Schema Part 2: Datatypes
    n


    Support in Xerces-J 1.4+
n
Type System Design Features
    Elements and attributes have explicit
n

    types
    Types can be defined independently
n

    Definitions
n

        Global
    n

        Local/Anonymous
    n
Two kinds of types
    Simple types
n

        describe character data
    n


    Complex types
n

        Can have attributes
    n

        Can have content models (elements)
    n
Example of simple type
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
<element name='withdraw' type=quot;integer“/>
</schema>
Simple types
    Lexical Space
n

    Value Space
n

    Facets
n

    Primitive built-in types
n

        XML 1.0 types
    n

        String, boolean, numbers, dates, times
    n
Creating new simple types
    Restriction
n
         <schema
    n
         xmlns='http://www.w3.org/2001/XMLSchema'>
         <element name='withdraw'>
          <simpleType>
           <restriction base='integer'>
            <minInclusive value=quot;0quot;/>
           </restriction>
          </simpleType>
         </element>
        </schema>

    Some built in types are restrictions of
n
    primitive types
Facets
    Numeric range restriction
n

        Miniumum and maximum
    n

        Inclusive / exclusive
    n


    Enumeration
n

        Explicit enumeration
    n


    Pattern – regular expressions
n

        Constrains strings
    n
Atomic vs non-Atomic types
    Atomic Types
n

    List
n
        <schema
    n

        xmlns='http://www.w3.org/2001/XMLSchema'>
         <element name='friends'>
          <simpleType>
          <list itemType='string'/>
          </simpleType>
         </element>
        </schema>

    Union
n
Example of complex type
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <element name='withdraw'>
  <complexType>
   <simpleContent>
      <extension base='integer'>
       <attribute name='currency‘ type='string'
                  default='us'/>
      </extension>
   </simpleContent>
  </complexType>
 </element>
</schema>
Complex types
    Carry attributes
n

    Can have child element content
n

    Can be derived from simple types
n
Content Models
    Complex types have content models to
n

    describe nested elements, etc.
    Content Model types
n

        SimpleContent – just content
    n

        element only content
    n

        ComplexContent – type derivation
    n

        Mixed Content – elements and content
    n

        Empty content
    n
Element Only Content
    <schema
n

        xmlns=‘http://www.w3.org/2001/XMLSchema’>
     <complexType name=‘person’>
      <sequence>
        <element name=‘name’ type=‘string’/>
        <element name=‘age’ type=‘positiveInteger’>
      </sequence>
     </complexType>
    </schema>
Compositors
    Three compositors
n

        <sequence>
    n

        <choice>
    n

        <all>
    n
Mixed Content
    Stricter than XML 1.0 – order and
n

    number of child elements counts
    Attribute on complexType or
n

    complexContent
Example of Mixed Content
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <element name='boilerplate'>
  <complexType mixed='true'>
   <all>
      <element name='heading' type='string'/>
      <element name='version' type='decimal'/>
      <element name='email' type='string'/>
   </all>
  </complexType>
 </element>
</schema>
Empty Content
 <schema
  xmlns='http://www.w3.org/2001/XMLSchema' >
  <complexType name=‘void’>
   <attribute name=‘size’ type=‘integer’/>
  </complexType>
 </schema>
minOccurs/maxOccurs
    How do I specify how many times an element
n
    occurs?

    <schema
      xmlns='http://www.w3.org/2001/XMLSchema' >
      <complexType name=‘friend’>
       <element name=‘lastName’ type=‘string’/>
       <element name=‘firstName’ type=‘string’/>
      </complexType>
      <element name=‘friends’>
       <sequence>
        <element name=‘friend’ minOccurs=‘0’
                 maxOccurs=‘unbounded’/>
       </sequence>
     </schema>
Attributes
    Use any simple type
n


    <attribute name=‘delayed’ type=‘boolean’
               use=‘optional’ default=‘false’/>

    <attribute name=‘ranking’
               type=‘positiveInteger’
               use=‘required’/>
ComplexType Extension
    Add to end of type
n


<schema xmlns='http://www.w3.org/2001/XMLSchema'>
   <complexType name='personType'>
   <sequence>
    <element name='name' type='string'/>
    <element name='father' type='string'/>
   </sequence>
   </complexType>
ComplexType Extension
<complexType name='parentType'>
 <complexContent>
  <extension base='personType'>
     <sequence>
      <element name='child' type='string'/>
      </sequence>
  </extension>
 </complexContent>
</complexType>
<element name='person' type='personType'/>
<element name='parent' type='parentType'/>
</schema>
ComplexType Restriction 1
    Must state restriction
n


<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <complexType name='personType'>
  <sequence>
   <element name='name' type='string'/>
   <element name='father' type='string'/>
  </sequence>
 </complexType>
ComplexType Restriction 2
<complexType name='orphanType'>
  <complexContent>
   <restriction base='personType'>
    <sequence>
     <element name='name' type='string'/>
    </sequence>
   </restriction>
  </complexContent>
 </complexType>

 <element name='person' type='personType'/>
 <element name='orphan' type='orphanType'/>
</schema>
Modularity constructs
    <group>
n

        For Content Models
    n


    <attributeGroup>
n

        For attributes
    n
Modularity Example
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <group name='phoneNumber'>
   <sequence>
    <element name='areaCode' type='positiveInteger'/>
    <element name='number' type='string'/>
   </sequence>
 </group>
 <attributeGroup name='callingAttributes'>
   <attribute name='callingCard' type='string'/>
 </attributeGroup>
 <element name='ISP'>
   <complexType>
    <group ref='phoneNumber'/>
    <attributeGroup ref='callingAttributes'/>
   </complexType>
 </element>
</schema>
Modularity vs inheritance
    Kohsuke Kawaguchi
n

    Model groups simulate inheritance,
n

    since they nest
    Restriction forces you to write it all out,
n

    so this is a model group as well
    Checking model groups is much easier
n

    than checking inheritance
Include
    For physical modularity of a schema
n

    Definitions in the same target
n

    namespace
    <include
n

    schemaLocation=‘http://www.schemas.com/fragment
    .xsd’/>
Target Namespaces
    To put a set of definitions into a
n

    namespace…

<schema xmlns='http://www.w3.org/2001/XMLSchema'
   targetNamespace='http://www.sauria.com/Schemas/Tutori
   al/target'>
 <element name='withdraw' type=quot;integer“/>
</schema>
Import
    Mix types from different namespaces
n

    Simple types can be used
n

        Must be global
    n

    Complex types can be used
n

        Named, global types only
    n

    Import element must appear first in
n
    schema
    Can also import and redefine imported
n
    items
Import Example 1
<schema
  xmlns='http://www.w3.org/2001/XMLSchema
  xmlns:beers='http://www.sauria.com/Schemas/Tuto
  rial/importee'
  targetNamespace='http://www.sauria.com/Schemas/
  Tutorial/importee‘
  elementFormDefault=‘qualified’>
  <complexType name='importedBeer'>
   <sequence>
    <element name='color' type='string'/>
    <element name='alcohol' type='decimal'/>
   </sequence>
  </complexType>
</schema>
Import Example 2
<schema
  xmlns='http://www.w3.org/2001/XMLSchema‘
  xmlns:importedBeerSchema='http://www.sauria.com
  /Schemas/Tutorial/importee‘
  targetNamespace='http://www.sauria.com/Schemas/
  Tutorial/importer‘
  elementFormDefault=‘qualified’>

  <import
  namespace='http://www.sauria.com/Schemas/Tutori
  al/importee‘ schemaLocation='importee.xsd'/>

  <element name='beer‘
         type='importedBeerSchema:importedBeer'/>

  </schema>
XML Schema Instance NS
    XML Schema Instance Namespace
n
          URI is
    n

          http://www.w3.org/2001/XMLSchema-instance
          Prefix is xsi
    n

    type
n
          Force an element to be associated with a
    n

          particular type
          <person xsi:type=‘parent’/>
    n


    nil
n
          For values that can be nil/null, specify the nil
    n

          value.
xsi:nil Example
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <complexType name='personType'>
  <sequence>
   <element name='name' type='string'/>
   <element name='father' type='string'/>
  </sequence>
 </complexType>
 <element name='person' type='personType'
  nillable='true'/>
</schema>

<person
  xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-
  instance’
  xsi:noNamespaceSchemaLocation='nil.xsd'
  xsi:nil='true'/>
Wildcards
    How do I leave a schema open for
n
    extension?
    “Any element from namespace x,y or z”
n

    “Any element from a namespace
n
    besides this one”
    “Any element from a schema in no
n
    namespace”
    “Any element from any namespace”
n

    Similarly for attributes
n
Wildcard Example 1
<schema xmlns='http://www.w3.org/2001/XMLSchema'
  xmlns:ann='http://www.sauria.com/Schemas/Tutori
  al/annonate'
  targetNamespace='http://www.sauria.com/Schemas/
  Tutorial/annonate‘
  elementFormDefault=‘qualified’>

 <complexType name='annotated'>
  <sequence>
   <element name='partName' type='string'/>
   <element name='partNo' type='integer'/>
   <element name='annotation'
     type='ann:annotation'/>
  </sequence>
 </complexType>
Wildcard Example 2
<complexType name='annotation'>
 <sequence>
  <any namespace='http://www.w3.org/1999/xhtml'
 processContents='lax'/>
 </sequence>
</complexType>

 <element name='part' type='ann:annotated'/>
</schema>
Annotation
    A standard way to document schemas
n

    <documentation> – for humans
n

    <appinfo> – for programs
n

    <annotation>
n

     <documentation>text here
     </documentation>
     <appinfo>
      <rdf-loc>http://www.schemas.com/rdf
      </rdf-loc>
     </appinfo>
    </annotation>
Uniqueness
    “I want to ensure that the value of an
n

    element <foo> is unique”
        In what scope? There may be two
    n

        elements named <foo>, each children of
        two different elements
        Specify the scope using XPath
    n
Unique Example 1
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <complexType name='bookType'>
   <sequence>
    <element name='title' type='string'/>
    <element name='ISBN' type='string'/>
   </sequence>
 </complexType>

<element name='books'>
  <complexType>
   <sequence>
    <element name='book' type='bookType'
  maxOccurs='unbounded'/>
   </sequence>
  </complexType>
</element>
Unique Example 2
 <unique name='isbn'>
  <selector xpath='books/book'/>
  <field xpath='ISBN'/>
 </unique>
</schema>
Keys
<schema xmlns='http://www.w3.org/2001/XMLSchema'>
 <complexType name='bookType'>
  <sequence>
   <element name='title' type='string'/>
   <element name='ISBN' type='string'/>
  </sequence>
 </complexType>

<complexType name='cardCatalog'>
 <sequence>
  <element name='cardNumber' type='string'/>
 </sequence>
</complexType>
Keys Example 1
<element name='books'>
 <complexType>
  <sequence>
     <element name='book' type='bookType'
 maxOccurs='unbounded'/>
     <element name='catalogCard'
 type='cardCatalog' maxOccurs='unbounded'/>
  </sequence>
 </complexType>
</element>
Keys Example 2
<unique name='isbn'>
   <selector xpath='books/book'/>
   <field xpath='ISBN'/>
 </unique>

<key name='card'>
  <selector xpath='books/book'/>
   <field xpath='ISBN'/>
</key>

 <keyref name='cardRef‘ refer=‘card’>
   <selector xpath='books/catalogCard'/>
   <field xpath='cardNumber'/>
 </keyref>
</schema>
Referencing a schema
    <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
n
    <withdraw
    xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance’
    xsi:noNamespaceSchemaLocation='simple.xsd'>
    25
    </withdraw>

    <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
n
    <bank:withdraw
    xmlns=‘http://www.schemas.com/bank’
    xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance’
    xsi:schemaLocation=‘http://www.schemas.com/bank
    simple.xsd'>
    25
    </bank:withdraw>
Tool support
    Xerces-J [ REC ]
n

    XSV [ REC ]
n

    Oracle XML Parser [ PR ]
n

    MSXML 4.0 [ PR ]
n
Cool Tool Tricks
    Use XSLT on your Schema
n

    Data Binding
n
Alternatives to XML Schema
    Some people feel XML Schema is too
n

    complicated
    Relax => TREX => Relax NG
n

        Relax (Murata Makoto)
    n

             Relax Verifier
         n


        TREX (James Clark)
    n

             JTREX
         n


        Relax NG (OASIS)
    n

             Jing
         n
Relax NG
    Uses XML Instance Syntax
n

    Supports namespaces
n

    Much simpler than XML Schema
n

    More orthogonal than XML Schema
n

    Can use XML Schema datatypes
n

    Doesn’t support uniqueness, inheritance
n
Relax NG Example
    <element name=‘book’ dataTypeLibrary=‘…’>
n
     <element name=‘title’>
       <data type=‘string’>
     </element>
     <element name=‘quantity’>
       <data type=‘integer’>
    </element>
    </element>

    <element name=‘books’>
     <oneOrMore>
       <ref name=‘book’/>
     </oneOrMore>
    </element>
Thank You!
    http://xml.apache.org
n

    twl@apache.org
n

Más contenido relacionado

La actualidad más candente (20)

Xml schema
Xml schemaXml schema
Xml schema
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTD
 
02 xml schema
02 xml schema02 xml schema
02 xml schema
 
Xsd examples
Xsd examplesXsd examples
Xsd examples
 
Introduction to xml schema
Introduction to xml schemaIntroduction to xml schema
Introduction to xml schema
 
XML and DTD
XML and DTDXML and DTD
XML and DTD
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
Dtd
DtdDtd
Dtd
 
XML's validation - DTD
XML's validation - DTDXML's validation - DTD
XML's validation - DTD
 
Introduction to xml
Introduction to xmlIntroduction to xml
Introduction to xml
 
Xsd
XsdXsd
Xsd
 
Xml Presentation-1
Xml Presentation-1Xml Presentation-1
Xml Presentation-1
 
Xml schema
Xml schemaXml schema
Xml schema
 
2 dtd - validating xml documents
2   dtd - validating xml documents2   dtd - validating xml documents
2 dtd - validating xml documents
 
Dtd
DtdDtd
Dtd
 
Document Type Definitions
Document Type DefinitionsDocument Type Definitions
Document Type Definitions
 
XML's validation - XML Schema
XML's validation - XML SchemaXML's validation - XML Schema
XML's validation - XML Schema
 
Dtd
DtdDtd
Dtd
 
XML Presentation-2
XML Presentation-2XML Presentation-2
XML Presentation-2
 
Xml Presentation-3
Xml Presentation-3Xml Presentation-3
Xml Presentation-3
 

Similar a IQPC Canada XML 2001: How to develop Syntax and XML Schema

35 schemas
35 schemas35 schemas
35 schemasmavilym
 
Relax NG, a Schema Language for XML
Relax NG, a Schema Language for XMLRelax NG, a Schema Language for XML
Relax NG, a Schema Language for XMLOverdue Books LLC
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18HUST
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARStephan Schmidt
 
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationIQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationTed Leung
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelyht4ever
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Languageyht4ever
 
Struts2
Struts2Struts2
Struts2yuvalb
 
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...phanleson
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xmlmussawir20
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskRichard Davis
 

Similar a IQPC Canada XML 2001: How to develop Syntax and XML Schema (20)

Xml Schema
Xml SchemaXml Schema
Xml Schema
 
35 schemas
35 schemas35 schemas
35 schemas
 
Relax NG, a Schema Language for XML
Relax NG, a Schema Language for XMLRelax NG, a Schema Language for XML
Relax NG, a Schema Language for XML
 
Xml
XmlXml
Xml
 
XML and XSLT
XML and XSLTXML and XSLT
XML and XSLT
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
XML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEARXML and Web Services with PHP5 and PEAR
XML and Web Services with PHP5 and PEAR
 
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic CommunicationIQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
IQPC Canada XML 2001: How to Use XML Parsing to Enhance Electronic Communication
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Why RDFa?
Why RDFa?Why RDFa?
Why RDFa?
 
Struts2
Struts2Struts2
Struts2
 
Struts2
Struts2Struts2
Struts2
 
Ridingapachecamel
RidingapachecamelRidingapachecamel
Ridingapachecamel
 
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...Xml For Dummies   Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
Xml For Dummies Chapter 10 Building A Custom Xml Schema it-slideshares.blog...
 
Php Simple Xml
Php Simple XmlPhp Simple Xml
Php Simple Xml
 
Everything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To AskEverything You Always Wanted To Know About XML But Were Afraid To Ask
Everything You Always Wanted To Know About XML But Were Afraid To Ask
 
What is xml
What is xmlWhat is xml
What is xml
 
XMLT
XMLTXMLT
XMLT
 

Más de Ted Leung

DjangoCon 2009 Keynote
DjangoCon 2009 KeynoteDjangoCon 2009 Keynote
DjangoCon 2009 KeynoteTed Leung
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Seeding The Cloud
Seeding The CloudSeeding The Cloud
Seeding The CloudTed Leung
 
Programming Languages For The Cloud
Programming Languages For The CloudProgramming Languages For The Cloud
Programming Languages For The CloudTed Leung
 
MySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQLMySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQLTed Leung
 
PyCon US 2009: Challenges and Opportunities for Python
PyCon US 2009: Challenges and Opportunities for PythonPyCon US 2009: Challenges and Opportunities for Python
PyCon US 2009: Challenges and Opportunities for PythonTed Leung
 
Northwest Python Day 2009
Northwest Python Day 2009Northwest Python Day 2009
Northwest Python Day 2009Ted Leung
 
PyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic LanguagesPyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic LanguagesTed Leung
 
OSCON 2008: Open Source Community Antipatterns
OSCON 2008: Open Source Community AntipatternsOSCON 2008: Open Source Community Antipatterns
OSCON 2008: Open Source Community AntipatternsTed Leung
 
OSCON 2007: Open Design, Not By Committee
OSCON 2007: Open Design, Not By CommitteeOSCON 2007: Open Design, Not By Committee
OSCON 2007: Open Design, Not By CommitteeTed Leung
 
Ignite The Web 2007
Ignite The Web 2007Ignite The Web 2007
Ignite The Web 2007Ted Leung
 
ApacheCon US 2007: Open Source Community Antipatterns
ApacheCon US 2007:  Open Source Community AntipatternsApacheCon US 2007:  Open Source Community Antipatterns
ApacheCon US 2007: Open Source Community AntipatternsTed Leung
 
OSCON 2005: Build Your Own Chandler Parcel
OSCON 2005: Build Your Own Chandler ParcelOSCON 2005: Build Your Own Chandler Parcel
OSCON 2005: Build Your Own Chandler ParcelTed Leung
 
PyCon 2005 PyBlosxom
PyCon 2005 PyBlosxomPyCon 2005 PyBlosxom
PyCon 2005 PyBlosxomTed Leung
 
SeaJUG March 2004 - Groovy
SeaJUG March 2004 - GroovySeaJUG March 2004 - Groovy
SeaJUG March 2004 - GroovyTed Leung
 
OSCON 2004: XML and Apache
OSCON 2004: XML and ApacheOSCON 2004: XML and Apache
OSCON 2004: XML and ApacheTed Leung
 
OSCON 2004: A Developer's Tour of Chandler
OSCON 2004: A Developer's Tour of ChandlerOSCON 2004: A Developer's Tour of Chandler
OSCON 2004: A Developer's Tour of ChandlerTed Leung
 
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJSeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJTed Leung
 
ApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML ParsingApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML ParsingTed Leung
 
SD Forum 1999 XML Lessons Learned
SD Forum 1999 XML Lessons LearnedSD Forum 1999 XML Lessons Learned
SD Forum 1999 XML Lessons LearnedTed Leung
 

Más de Ted Leung (20)

DjangoCon 2009 Keynote
DjangoCon 2009 KeynoteDjangoCon 2009 Keynote
DjangoCon 2009 Keynote
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Seeding The Cloud
Seeding The CloudSeeding The Cloud
Seeding The Cloud
 
Programming Languages For The Cloud
Programming Languages For The CloudProgramming Languages For The Cloud
Programming Languages For The Cloud
 
MySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQLMySQL User Conference 2009: Python and MySQL
MySQL User Conference 2009: Python and MySQL
 
PyCon US 2009: Challenges and Opportunities for Python
PyCon US 2009: Challenges and Opportunities for PythonPyCon US 2009: Challenges and Opportunities for Python
PyCon US 2009: Challenges and Opportunities for Python
 
Northwest Python Day 2009
Northwest Python Day 2009Northwest Python Day 2009
Northwest Python Day 2009
 
PyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic LanguagesPyCon UK 2008: Challenges for Dynamic Languages
PyCon UK 2008: Challenges for Dynamic Languages
 
OSCON 2008: Open Source Community Antipatterns
OSCON 2008: Open Source Community AntipatternsOSCON 2008: Open Source Community Antipatterns
OSCON 2008: Open Source Community Antipatterns
 
OSCON 2007: Open Design, Not By Committee
OSCON 2007: Open Design, Not By CommitteeOSCON 2007: Open Design, Not By Committee
OSCON 2007: Open Design, Not By Committee
 
Ignite The Web 2007
Ignite The Web 2007Ignite The Web 2007
Ignite The Web 2007
 
ApacheCon US 2007: Open Source Community Antipatterns
ApacheCon US 2007:  Open Source Community AntipatternsApacheCon US 2007:  Open Source Community Antipatterns
ApacheCon US 2007: Open Source Community Antipatterns
 
OSCON 2005: Build Your Own Chandler Parcel
OSCON 2005: Build Your Own Chandler ParcelOSCON 2005: Build Your Own Chandler Parcel
OSCON 2005: Build Your Own Chandler Parcel
 
PyCon 2005 PyBlosxom
PyCon 2005 PyBlosxomPyCon 2005 PyBlosxom
PyCon 2005 PyBlosxom
 
SeaJUG March 2004 - Groovy
SeaJUG March 2004 - GroovySeaJUG March 2004 - Groovy
SeaJUG March 2004 - Groovy
 
OSCON 2004: XML and Apache
OSCON 2004: XML and ApacheOSCON 2004: XML and Apache
OSCON 2004: XML and Apache
 
OSCON 2004: A Developer's Tour of Chandler
OSCON 2004: A Developer's Tour of ChandlerOSCON 2004: A Developer's Tour of Chandler
OSCON 2004: A Developer's Tour of Chandler
 
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJSeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
SeaJUG Dec 2001: Aspect-Oriented Programming with AspectJ
 
ApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML ParsingApacheCon 2000 Everything you ever wanted to know about XML Parsing
ApacheCon 2000 Everything you ever wanted to know about XML Parsing
 
SD Forum 1999 XML Lessons Learned
SD Forum 1999 XML Lessons LearnedSD Forum 1999 XML Lessons Learned
SD Forum 1999 XML Lessons Learned
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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...DianaGray10
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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, Adobeapidays
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
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...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

IQPC Canada XML 2001: How to develop Syntax and XML Schema

  • 1. How to develop Syntax and XML Schema Ted Leung Chairman, ASF XML PMC Principal, Sauria Associates, LLC twl@sauria.com
  • 2. Thank You ASF n Xerces-J-Dev n Xerces-J-User n
  • 3. Outline Overview n xml.apache.org project n Business / Technical motivation for XML n Schema Coverage of Key XML Schema Features n Alternative Schema Languages n
  • 4. Apache Software Foundation Non-profit foundation n volunteers n Open Source Software n Apache License n Not viral like GPL n Commercial Use is fine n Projects n Web Server n jakarta.apache.org n JSP, Servlets, Ant, Struts, Server Frameworks n xml.apache.org n
  • 5. xml.apache.org Part of the Apache Software Foundation n Open Source XML processing n components XML Parser [Xerces] (Java, C++, Perl) n XSLT processor [Xalan] (Java, C++) n XSL Formatting Objects [FOP] n SVG [Batik] n Cocoon n SOAP [Apache-SOAP / Axis] n
  • 6. Business Motivation XML is a language of agreements n We needed a way to specify those n agreements in more detail – raises the level of discourse between applications We needed a way for machines to be n able to do more with those agreements
  • 7. Technical Motivation Three major needs leading up to XML n Schema Strong data typing of element content and n attributes – push more validation into the XML infrastructure Integration of namespaces into grammars n Use of XML syntax to describe the n grammar
  • 8. When would you use Schema? You have rich data types [typing] n You need open content models n [wildcards] You need to combine data from multiple n organzations [namespaces] You are mapping from database n [uniqueness]
  • 9. Example Schema Applications SOAP / WSDL n XSLT 2 n XForms n Many more to come n
  • 10. XML Schema Specification W3C Recommendation as of 5/2/2001 n Three documents: n XML Schema Part 0: Primer n XML Schema Part 1: Structures n XML Schema Part 2: Datatypes n Support in Xerces-J 1.4+ n
  • 11. Type System Design Features Elements and attributes have explicit n types Types can be defined independently n Definitions n Global n Local/Anonymous n
  • 12. Two kinds of types Simple types n describe character data n Complex types n Can have attributes n Can have content models (elements) n
  • 13. Example of simple type <schema xmlns='http://www.w3.org/2001/XMLSchema'> <element name='withdraw' type=quot;integer“/> </schema>
  • 14. Simple types Lexical Space n Value Space n Facets n Primitive built-in types n XML 1.0 types n String, boolean, numbers, dates, times n
  • 15. Creating new simple types Restriction n <schema n xmlns='http://www.w3.org/2001/XMLSchema'> <element name='withdraw'> <simpleType> <restriction base='integer'> <minInclusive value=quot;0quot;/> </restriction> </simpleType> </element> </schema> Some built in types are restrictions of n primitive types
  • 16. Facets Numeric range restriction n Miniumum and maximum n Inclusive / exclusive n Enumeration n Explicit enumeration n Pattern – regular expressions n Constrains strings n
  • 17. Atomic vs non-Atomic types Atomic Types n List n <schema n xmlns='http://www.w3.org/2001/XMLSchema'> <element name='friends'> <simpleType> <list itemType='string'/> </simpleType> </element> </schema> Union n
  • 18. Example of complex type <schema xmlns='http://www.w3.org/2001/XMLSchema'> <element name='withdraw'> <complexType> <simpleContent> <extension base='integer'> <attribute name='currency‘ type='string' default='us'/> </extension> </simpleContent> </complexType> </element> </schema>
  • 19. Complex types Carry attributes n Can have child element content n Can be derived from simple types n
  • 20. Content Models Complex types have content models to n describe nested elements, etc. Content Model types n SimpleContent – just content n element only content n ComplexContent – type derivation n Mixed Content – elements and content n Empty content n
  • 21. Element Only Content <schema n xmlns=‘http://www.w3.org/2001/XMLSchema’> <complexType name=‘person’> <sequence> <element name=‘name’ type=‘string’/> <element name=‘age’ type=‘positiveInteger’> </sequence> </complexType> </schema>
  • 22. Compositors Three compositors n <sequence> n <choice> n <all> n
  • 23. Mixed Content Stricter than XML 1.0 – order and n number of child elements counts Attribute on complexType or n complexContent
  • 24. Example of Mixed Content <schema xmlns='http://www.w3.org/2001/XMLSchema'> <element name='boilerplate'> <complexType mixed='true'> <all> <element name='heading' type='string'/> <element name='version' type='decimal'/> <element name='email' type='string'/> </all> </complexType> </element> </schema>
  • 25. Empty Content <schema xmlns='http://www.w3.org/2001/XMLSchema' > <complexType name=‘void’> <attribute name=‘size’ type=‘integer’/> </complexType> </schema>
  • 26. minOccurs/maxOccurs How do I specify how many times an element n occurs? <schema xmlns='http://www.w3.org/2001/XMLSchema' > <complexType name=‘friend’> <element name=‘lastName’ type=‘string’/> <element name=‘firstName’ type=‘string’/> </complexType> <element name=‘friends’> <sequence> <element name=‘friend’ minOccurs=‘0’ maxOccurs=‘unbounded’/> </sequence> </schema>
  • 27. Attributes Use any simple type n <attribute name=‘delayed’ type=‘boolean’ use=‘optional’ default=‘false’/> <attribute name=‘ranking’ type=‘positiveInteger’ use=‘required’/>
  • 28. ComplexType Extension Add to end of type n <schema xmlns='http://www.w3.org/2001/XMLSchema'> <complexType name='personType'> <sequence> <element name='name' type='string'/> <element name='father' type='string'/> </sequence> </complexType>
  • 29. ComplexType Extension <complexType name='parentType'> <complexContent> <extension base='personType'> <sequence> <element name='child' type='string'/> </sequence> </extension> </complexContent> </complexType> <element name='person' type='personType'/> <element name='parent' type='parentType'/> </schema>
  • 30. ComplexType Restriction 1 Must state restriction n <schema xmlns='http://www.w3.org/2001/XMLSchema'> <complexType name='personType'> <sequence> <element name='name' type='string'/> <element name='father' type='string'/> </sequence> </complexType>
  • 31. ComplexType Restriction 2 <complexType name='orphanType'> <complexContent> <restriction base='personType'> <sequence> <element name='name' type='string'/> </sequence> </restriction> </complexContent> </complexType> <element name='person' type='personType'/> <element name='orphan' type='orphanType'/> </schema>
  • 32. Modularity constructs <group> n For Content Models n <attributeGroup> n For attributes n
  • 33. Modularity Example <schema xmlns='http://www.w3.org/2001/XMLSchema'> <group name='phoneNumber'> <sequence> <element name='areaCode' type='positiveInteger'/> <element name='number' type='string'/> </sequence> </group> <attributeGroup name='callingAttributes'> <attribute name='callingCard' type='string'/> </attributeGroup> <element name='ISP'> <complexType> <group ref='phoneNumber'/> <attributeGroup ref='callingAttributes'/> </complexType> </element> </schema>
  • 34. Modularity vs inheritance Kohsuke Kawaguchi n Model groups simulate inheritance, n since they nest Restriction forces you to write it all out, n so this is a model group as well Checking model groups is much easier n than checking inheritance
  • 35. Include For physical modularity of a schema n Definitions in the same target n namespace <include n schemaLocation=‘http://www.schemas.com/fragment .xsd’/>
  • 36. Target Namespaces To put a set of definitions into a n namespace… <schema xmlns='http://www.w3.org/2001/XMLSchema' targetNamespace='http://www.sauria.com/Schemas/Tutori al/target'> <element name='withdraw' type=quot;integer“/> </schema>
  • 37. Import Mix types from different namespaces n Simple types can be used n Must be global n Complex types can be used n Named, global types only n Import element must appear first in n schema Can also import and redefine imported n items
  • 38. Import Example 1 <schema xmlns='http://www.w3.org/2001/XMLSchema xmlns:beers='http://www.sauria.com/Schemas/Tuto rial/importee' targetNamespace='http://www.sauria.com/Schemas/ Tutorial/importee‘ elementFormDefault=‘qualified’> <complexType name='importedBeer'> <sequence> <element name='color' type='string'/> <element name='alcohol' type='decimal'/> </sequence> </complexType> </schema>
  • 39. Import Example 2 <schema xmlns='http://www.w3.org/2001/XMLSchema‘ xmlns:importedBeerSchema='http://www.sauria.com /Schemas/Tutorial/importee‘ targetNamespace='http://www.sauria.com/Schemas/ Tutorial/importer‘ elementFormDefault=‘qualified’> <import namespace='http://www.sauria.com/Schemas/Tutori al/importee‘ schemaLocation='importee.xsd'/> <element name='beer‘ type='importedBeerSchema:importedBeer'/> </schema>
  • 40. XML Schema Instance NS XML Schema Instance Namespace n URI is n http://www.w3.org/2001/XMLSchema-instance Prefix is xsi n type n Force an element to be associated with a n particular type <person xsi:type=‘parent’/> n nil n For values that can be nil/null, specify the nil n value.
  • 41. xsi:nil Example <schema xmlns='http://www.w3.org/2001/XMLSchema'> <complexType name='personType'> <sequence> <element name='name' type='string'/> <element name='father' type='string'/> </sequence> </complexType> <element name='person' type='personType' nillable='true'/> </schema> <person xmlns:xsi=‘http://www.w3.org/2001/XMLSchema- instance’ xsi:noNamespaceSchemaLocation='nil.xsd' xsi:nil='true'/>
  • 42. Wildcards How do I leave a schema open for n extension? “Any element from namespace x,y or z” n “Any element from a namespace n besides this one” “Any element from a schema in no n namespace” “Any element from any namespace” n Similarly for attributes n
  • 43. Wildcard Example 1 <schema xmlns='http://www.w3.org/2001/XMLSchema' xmlns:ann='http://www.sauria.com/Schemas/Tutori al/annonate' targetNamespace='http://www.sauria.com/Schemas/ Tutorial/annonate‘ elementFormDefault=‘qualified’> <complexType name='annotated'> <sequence> <element name='partName' type='string'/> <element name='partNo' type='integer'/> <element name='annotation' type='ann:annotation'/> </sequence> </complexType>
  • 44. Wildcard Example 2 <complexType name='annotation'> <sequence> <any namespace='http://www.w3.org/1999/xhtml' processContents='lax'/> </sequence> </complexType> <element name='part' type='ann:annotated'/> </schema>
  • 45. Annotation A standard way to document schemas n <documentation> – for humans n <appinfo> – for programs n <annotation> n <documentation>text here </documentation> <appinfo> <rdf-loc>http://www.schemas.com/rdf </rdf-loc> </appinfo> </annotation>
  • 46. Uniqueness “I want to ensure that the value of an n element <foo> is unique” In what scope? There may be two n elements named <foo>, each children of two different elements Specify the scope using XPath n
  • 47. Unique Example 1 <schema xmlns='http://www.w3.org/2001/XMLSchema'> <complexType name='bookType'> <sequence> <element name='title' type='string'/> <element name='ISBN' type='string'/> </sequence> </complexType> <element name='books'> <complexType> <sequence> <element name='book' type='bookType' maxOccurs='unbounded'/> </sequence> </complexType> </element>
  • 48. Unique Example 2 <unique name='isbn'> <selector xpath='books/book'/> <field xpath='ISBN'/> </unique> </schema>
  • 49. Keys <schema xmlns='http://www.w3.org/2001/XMLSchema'> <complexType name='bookType'> <sequence> <element name='title' type='string'/> <element name='ISBN' type='string'/> </sequence> </complexType> <complexType name='cardCatalog'> <sequence> <element name='cardNumber' type='string'/> </sequence> </complexType>
  • 50. Keys Example 1 <element name='books'> <complexType> <sequence> <element name='book' type='bookType' maxOccurs='unbounded'/> <element name='catalogCard' type='cardCatalog' maxOccurs='unbounded'/> </sequence> </complexType> </element>
  • 51. Keys Example 2 <unique name='isbn'> <selector xpath='books/book'/> <field xpath='ISBN'/> </unique> <key name='card'> <selector xpath='books/book'/> <field xpath='ISBN'/> </key> <keyref name='cardRef‘ refer=‘card’> <selector xpath='books/catalogCard'/> <field xpath='cardNumber'/> </keyref> </schema>
  • 52. Referencing a schema <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> n <withdraw xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance’ xsi:noNamespaceSchemaLocation='simple.xsd'> 25 </withdraw> <?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?> n <bank:withdraw xmlns=‘http://www.schemas.com/bank’ xmlns:xsi=‘http://www.w3.org/2001/XMLSchema-instance’ xsi:schemaLocation=‘http://www.schemas.com/bank simple.xsd'> 25 </bank:withdraw>
  • 53. Tool support Xerces-J [ REC ] n XSV [ REC ] n Oracle XML Parser [ PR ] n MSXML 4.0 [ PR ] n
  • 54. Cool Tool Tricks Use XSLT on your Schema n Data Binding n
  • 55. Alternatives to XML Schema Some people feel XML Schema is too n complicated Relax => TREX => Relax NG n Relax (Murata Makoto) n Relax Verifier n TREX (James Clark) n JTREX n Relax NG (OASIS) n Jing n
  • 56. Relax NG Uses XML Instance Syntax n Supports namespaces n Much simpler than XML Schema n More orthogonal than XML Schema n Can use XML Schema datatypes n Doesn’t support uniqueness, inheritance n
  • 57. Relax NG Example <element name=‘book’ dataTypeLibrary=‘…’> n <element name=‘title’> <data type=‘string’> </element> <element name=‘quantity’> <data type=‘integer’> </element> </element> <element name=‘books’> <oneOrMore> <ref name=‘book’/> </oneOrMore> </element>
  • 58. Thank You! http://xml.apache.org n twl@apache.org n