620 likes | 705 Views
DEV-13: XML Schema to the Rescue. Michael Resnick Principal Software Engineer. Under Development. D I S C L A I M E R. D I S C L A I M E R. This talk includes information about potential future products and/or product enhancements.
E N D
DEV-13:XML Schema to the Rescue Michael Resnick Principal Software Engineer
Under Development D I S C L A I M E R D I S C L A I M E R • This talk includes information about potential future products and/or product enhancements. • What I am going to say reflects our current thinking, but the information contained herein is preliminary and subject to change. Any future products we ultimately deliver may be materially different from what is described here. DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
What Is XML Schema? • An XML syntax • Describes structure of an XML document • Describes data types • Similar to OpenEdge™ table schema DEV-13: XML Schema to the Rescue
XML Schema Example - Schema XML Schema Fragment <schema> <element name=“name”> <complexType> <sequence> <element name=“first” type=“string”/> <element name=“last” type=“string”/> </sequence> </complexType> </element> </schema> DEV-13: XML Schema to the Rescue
XML Schema Example - Instance XML Instance <name> <first>Alfred</first> <last>Newman</last> </name> DEV-13: XML Schema to the Rescue
XML Schema – Why? • Validation • Improvement over document type definitions (DTDs) • Concise reference for XML vocabulary • XML becoming ubiquitous • Storage format • Messaging format DEV-13: XML Schema to the Rescue
Existing XML Schemas • Vertical markets standards • MISMO – mortgages • HIPAA – medical • Horizontal market standards • ebXML (e-business exchange) • WS-Security • Others • Commonwealth of Massachusetts DEV-13: XML Schema to the Rescue
Using an XML Schema to Validate XML Schema Document XML Document (refers to X.xsd) Validating Parser X.xml X.xsd Validated XML Document DEV-13: XML Schema to the Rescue
XML Schema Compared to DTD • Richer set of data types • More detail about data type • Is an XML syntax • Extensible DEV-13: XML Schema to the Rescue
XML Schema 1.0 Specifications • W3C Recommendation: 2001 • Second edition: 2004 DEV-13: XML Schema to the Rescue
XML Schema Specifications - New • XML Schema 1.1: 24 February 2005 (Working Draft) • Simplification • Namespace versioning • Corrections • Minor data type extensions • Schema Component Designators:29 March 2005 (Last Call Working Draft) DEV-13: XML Schema to the Rescue
XML Schema – What does it do? • Defines structured documents • Progress Tables • Relational Database table • Programming language structures • Defines semi-structured documents • XHTML • DocBook • SOAP • Defines an XML namespace DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
Use in the 4GL • Currently • 4GL web service provider • 4GL web service client • Release 10.1A • DOM API • SAX Reader API • ProDataSet andTEMP-TABLE serialization } SOAP } Explicit (de)serialization } Automatic (de)serialization DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
XML Namespaces • Mix different XML vocabularies <bib:book xmlns:bib=“urn:biblio” xmlns:pn=“http://schemas/personalName”> <bib:title>Madmiration</bib:title> <bib:author> <pn:name> <pn:title>Dr.</pn:title> <pn:first>Alfred</pn:first> <pn:middleInit>E</pn:middleInit> <pn:last>Newman</pn:last> </pn:name> </bib:author> </bib:book> DEV-13: XML Schema to the Rescue
Namespaces • Elements known by two values:Namespace (URI) Local nameurn:biblio titlehttp://schemas/personalName title • Prefix is an artifact of serializationbib pn • Prefix associated with namespace using xmlns:prefix=“namespace-uri” construct DEV-13: XML Schema to the Rescue
Default Namespace • Allows for elements without a prefix to be part of a namespace. <title xmlns=“urn:biblio”>…</title> DEV-13: XML Schema to the Rescue
No Namespace • Use no namespace declarations. <title>…</title> DEV-13: XML Schema to the Rescue
Namespace Prefix Scope Namespace is visible for all elements appearing within its declaration <ns:book xmlns:ns=“urn:biblio”> <ns:title>...</ns:title> <ns:author> <ns:name xmlns:ns=“http://schemas/personName”> <ns:title>...</ns:title> ... </ns:name> </ns:author> </ns:book> DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
Simple Data Types • The string of characters within an element or an attribute value<anElement anAttribute=“simple-type”>simple-type</anElement> • Definition specifies • string representations: “0001234”, “+1234” • limitations (facets) on value:0 < x < 10, password 6-10 characters long DEV-13: XML Schema to the Rescue
Simple Data Types anyType 40+ simple types anySimpleType all complex types dateTime decimal string integer long DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
Complex Data Types - Structures • A construct of simple types • sequence (data structure) • choice (union) • all (order unimportant) <name> <first></first> <middle></middle> <last></last></name> name last middle first DEV-13: XML Schema to the Rescue
Complex Data Types - Content • Content can be • elements • attributes • mixed (elements and text à la XHTML) DEV-13: XML Schema to the Rescue
Complex Data - Model Element Text Attribute DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Attributes • Elements • Groups • Keys, Keyrefs and Unique • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
Attributes • Always defined by simple type • Specify use: optional, required or fixed • Specify default value XML Schema Fragment <attribute name=“count” type=“integer” default=“1” use=“optional”/> XML Instance <elementcount=“5”>content</element> DEV-13: XML Schema to the Rescue
Elements • Define by a type (simple or complex) • Expresses parent/child relationship • May have attributes DEV-13: XML Schema to the Rescue
Elements • Can specify extent (minOccurs/maxOccurs) • Mandatory singleton minOccurs=1 maxOccurs=1 • Optional singleton minOccurs=0 maxOccurs=1 • Fixed length array minOccurs=n maxOccurs=n • Variable length array minOccurs=m maxOccurs=n • Nilability (true/false) ≈ UNKNOWN allowed? DEV-13: XML Schema to the Rescue
Defining an Element XML Schema Fragment <element name=“lineItem” type=“string” minOccurs=“1” maxOccurs=“unbounded” nillable=“false”><attribute name=“lineNumber” type=“int”/> </element> XML Instance <lineItem lineNumber=“1”>widget</lineItem> <lineItem lineNumber=“15”>gadget</lineItem> DEV-13: XML Schema to the Rescue
Groups (Element) andAttributeGroups • Reusable “macros” • Inline inclusion of elements/attributes DEV-13: XML Schema to the Rescue
Group Example:Definition and Reference XML Schema Fragment <group name=“names”> <sequence> <element name=“firstName” type=“string”/> <element name=“lastName” type=“string”/> </sequence> </group> <element name=“name”> <sequence> <element name=“title” type=“string”/> <group ref=“names”/> </seqeuence> </element> DEV-13: XML Schema to the Rescue
Group Instance XML Instance <name> <title>Mr.</title> <firstName>Alfred</firstName> <lastName>Newman</lastName> </name> DEV-13: XML Schema to the Rescue
Unique • Unique • element or attribute values in a sequence must be unique <recordlist> <record><id>1</id><name>foo</name></record> <record><id>2</id><name>bar</name></record> <record><id>3</id><name>baz</name></record> </recordlist> DEV-13: XML Schema to the Rescue
Keys and Keyrefs • Keys – Same as Unique plus: • Must not be nil • Can be referenced by keyref • Similar to XML id attributes • Keyrefs • Defines a relationship between two constructs (attributes or elements) • Similar to HTML href attribute DEV-13: XML Schema to the Rescue
Keys and Keyrefs - Model Element Text Attribute Keyref DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Data types • Language • Demonstration DEV-13: XML Schema to the Rescue
Extensibility:Simple Type Derivation by Restriction integer …0123 -(264) <= n <= 264 - 1 long decimal ...0123[.4560…] DEV-13: XML Schema to the Rescue
Extensibility:Complex Type Derivation by Extension DEV-13: XML Schema to the Rescue
Extensibility:Complex Type Derivation by Restriction DEV-13: XML Schema to the Rescue
Extensibility: XML Schema Language • Can add your own XML Schema • elements • attributes • annotations • Useful for • storing and retrieving extra information • sending extra information DEV-13: XML Schema to the Rescue
Extensibility: Schema Language Modularity • Import – Combine schema definitions • Include – Organize complex definition Import Include DEV-13: XML Schema to the Rescue
Agenda • Introduction • Use in the 4GL • Namespaces • Simple Data Types • Complex Data Types • XML Constructs • Extensibility • Demonstration DEV-13: XML Schema to the Rescue
New Schema Document DEV-13: XML Schema to the Rescue
Complex name Element DEV-13: XML Schema to the Rescue
Fully Define Complex name Element DEV-13: XML Schema to the Rescue
SingleChar Type Definition DEV-13: XML Schema to the Rescue