Architecting XML Schemas for Oracle XML DB September
Architecting XML Schemas for Oracle XML DB September 10 th, 2003 Alexander Falk President, CEO – Altova, Inc. Member W 3 C Advisory Committee © 2003 Altova Gmb. H. All Rights Reserved.
Alexander Falk Bio ► Co-founded ALTOVA in 1992 ► Wrote XML Parser and XML Schema Validator used within XMLSPY ► Member of W 3 C XML Schema WG in 2001 ► Member of W 3 C Advisory Committee © 2003 Altova Gmb. H. All Rights Reserved.
Agenda ► XML Schema Overview ► Schema Components ► Architecting XML Schemas ► Data Mapping & Transformations ► XML Schema & Oracle XML DB ► Tools for XML Schemas ► Live Demonstration ► Q&A © 2003 Altova Gmb. H. All Rights Reserved.
What is XML Schema? ► DTDs not sufficient for data modeling ► XML-Data, XDR, SOX, . . . XML Schema ► Object-Oriented Features ► à Distinction between types and instances à Inheritance à Support for static vs. Dynamic types Make it easy to translate from programming languages to XML and vice versa © 2003 Altova Gmb. H. All Rights Reserved.
DTD‘s in a Nutshell ► ► Document Type Definitions (DTDs) à Uses special syntax (SGML-like) à Everything is a string (#PCDATA) à Reuse only through macros (parameter entities) à Concise syntax (although somewhat cryptic) Example: <!ELEMENT Age (#PCDATA)> © 2003 Altova Gmb. H. All Rights Reserved.
Cross-Referencing XML with DTD’s File “Person. xml” File “Person. dtd” <? xml version="1. 0" encoding="UTF-8"? > <!DOCTYPE Person SYSTEM "Person. dtd"> <!ELEMENT Person (First, Middle? , Last, Age)> <Person> <!ELEMENT First (#PCDATA)> <First>Alexander</First> <!ELEMENT Middle (#PCDATA)> <Last>Falk</Last> <!ELEMENT Last (#PCDATA)> <Age>34</Age> <!ELEMENT Age (#PCDATA)> </Person> © 2003 Altova Gmb. H. All Rights Reserved.
Schema in a Nutshell ► ► XML Schema à Uses XML syntax à Uses Datatypes: built-in and custom-defined à Reuse through groups and inheritance à Verbose syntax (more easily readable) Example: <element name=“Age” type=“integer”/> © 2003 Altova Gmb. H. All Rights Reserved.
Cross-Referencing XML with Schemas File “Person. xml” <? xml version="1. 0" encoding="UTF-8"? > <Person xmlns: xsi="http: //www. w 3. org/ 2001/XMLSchema-instance" xsi: no. Namespace. Schema. Location=" Person. xsd"> <First>Alexander</First> <Last>Falk</Last> <Age>34</Age> </Person> © 2003 Altova Gmb. H. All Rights Reserved. File “Person. xsd” <? xml version="1. 0" encoding="UTF-8"? > <xs: schema xmlns: xs="http: //www. w 3. org/2001/ XMLSchema"> <xs: element name="Person"> <xs: complex. Type> <xs: sequence> <xs: element name="First“ type="xs: string"/> <xs: element name="Middle“ type="xs: string“ min. Occurs="0"/> <xs: element name="Last“ type="xs: string"/> <xs: element name="Age“ type="xs: integer"/> </xs: sequence> </xs: complex. Type> </xs: element> </xs: schema>
XML Schema - Benefits ► Huge industry support (Oracle, BEA, Microsoft, IBM, etc. ) ► Information modeling in XML ► Representing OO capabilities in XML data ► ► Offloading consistency checking to the validation process in the XML parser Cost-saving through reduced development time © 2003 Altova Gmb. H. All Rights Reserved.
Schema Components ►Elements and their content model © 2003 Altova Gmb. H. All Rights Reserved. <element name="item"> <annotation><documentation>One item of a purchase order with its details</documentation></annotation> <complex. Type> <sequence> <choice> <element name="product. Name" type="string"/> </choice> <element name="quantity"> <simple. Type> <restriction base="positive. Integer"> <max. Exclusive value="100"/> </restriction> </simple. Type> </element> <element name="price" type="decimal"> <annotation><documentation>Needs to be specified in US$</documentation></annotation> </element> <element ref="ipo: comment" min. Occurs="0" max. Occurs="5"/> <element name="ship. Date" type="date" min. Occurs="0"/> </sequence> <attribute name="part. Num" type="ipo: Sku"/> </complex. Type> </element>
Schema Components ►Attributes and Attribute Groups <xs: attribute name="name" type="xs: NCName"/> <xs: attribute name="mixed" type="xs: boolean" use="optional" default="false"/> <xs: attribute name="abstract" type="xs: boolean" use="optional" default="false"/> <xs: attribute name="final" type="xs: derivation. Set"/> <xs: attribute name="block" type="xs: derivation. Set"/> © 2003 Altova Gmb. H. All Rights Reserved.
Schema Components © 2003 Altova Gmb. H. All Rights Reserved. ►Complex. Types and Substitution. Groups <xsd: complex. Type name="Person. Type"> <xsd: sequence> <xsd: element name="First" type="xsd: string"/> <xsd: element name="Last" type="xsd: string"/> <xsd: element name="Title" type="xsd: string“ min. Occurs="0"/> <xsd: element name="Phone. Ext" type="xsd: int"/> <xsd: element ref="EMail"/> </xsd: sequence> </xsd: complex. Type> <xsd: element name="Person" type="Person. Type"/> <xsd: element name="VIP“ substitution. Group="Person"> <xsd: complex. Type> <xsd: complex. Content> <xsd: extension base="Person. Type"> <xsd: attribute name="IQ" type="xsd: int"/> </xsd: extension> </xsd: complex. Content> </xsd: complex. Type> </xsd: element>
Schema Components ►Extension of Complex. Type © 2003 Altova Gmb. H. All Rights Reserved. <complex. Type name="Address"> <sequence> <element name="name" type="string“ min. Occurs="0"/> <element name="street“ type="string"/> <element name="city" type="string"/> </sequence> </complex. Type> <complex. Type name="US-Address"> <complex. Content> <extension base="ipo: Address"> <sequence> <element name="state“ type="ipo: US-State"/> <element name="zip“ type="positive. Integer"/> </sequence> </extension> </complex. Content> </complex. Type>
Schema Components ►Defining your own Simple. Types <xs: simple. Type name="toddler. Counting"> <xs: union> <xs: simple. Type> <xs: restriction base="xs: int"> <xs: min. Inclusive value="1"/> <xs: max. Inclusive value="3"/> </xs: restriction> </xs: simple. Type> <xs: restriction base="xs: string"> <xs: enumeration value="many"/> </xs: restriction> </xs: simple. Type> </xs: union> </xs: simple. Type> © 2003 Altova Gmb. H. All Rights Reserved.
Architecting XML Schemas ► From Scratch à ► By Example (Use-Cases) à ► Using established OO methodologies, using Schema design tools, from OO class libraries (Java, C++, etc. ) From any set of existing XML documents By Conversion à From existing DTD, DCD, or other schema à From SQL Database Schema © 2003 Altova Gmb. H. All Rights Reserved.
Data Mapping & Transformations ►Schema-based mapping ►Integrate data from different sources ►Web Services © 2003 Altova Gmb. H. All Rights Reserved.
XML Schema & Oracle XML DB ► ► ► XML Schema is central to Oracle 9 i It describes how XML documents are stored inside the database It allows validation of XML documents in the database © 2003 Altova Gmb. H. All Rights Reserved.
Extending XML Schema for Oracle 9 i ► Use SQLName to specify column names ► Use SQLType to specify storage datatype <? xml version="1. 0" encoding="UTF-8"? > <xs: schema xmlns: xs="http: //www. w 3. org/2001/XMLSchema“ xmlns: xdb="http: //xmlns. oracle. com/xdb"> <xs: complex. Type name=“Person. Type“ xdb: SQLType=“PERSON_TYPE"> <xs: sequence> <xs: element name="First“ type="xs: string“ xdb: SQLName=“FIRST_NM" xdb: SQLType=“NVARCHAR 2"/> <xs: element name="Middle“ type="xs: string“ min. Occurs="0" xdb: SQLName=“MIDDLE_NM" xdb: SQLType="NVARCHAR 2"/> <xs: element name="Last“ type="xs: string" xdb: SQLName=“LAST_NM" xdb: SQLType="NVARCHAR 2"/> <xs: element name="Age“ type="xs: short" xdb: SQLName=“PERSON_AGE" xdb: SQLType=“NUMBER"/> </xs: sequence> </xs: complex. Type></xs: schema> © 2003 Altova Gmb. H. All Rights Reserved.
XML Schema – Tools Overview ► ► Graphical Schema Editors à Visual Studio. NET à xmlspy® 2004 Mapping & Transformation Tools à ► mapforce™ 2004 Parsers à Oracle XML DB à Xerces à MSXML 4. 0 & System. XML (. NET Framework) © 2003 Altova Gmb. H. All Rights Reserved.
Demo Time Live Demonstration © 2003 Altova Gmb. H. All Rights Reserved.
► Questions & Answers © 2003 Altova Gmb. H. All Rights Reserved. XMLSPY, AUTHENTIC, STYLEVISION, MAPFORCE, MARKUP YOUR MIND, AXAD, NANONULL, and ALTOVA are trademarks of Altova Gmb. H (registered in numerous countries). All other trademarks are the property of their respective owners.
- Slides: 21