260 likes | 428 Views
Enterprise IT [Πληροφοριακές Τεχνολογίες της Επιχείρησης] Lecture 6-9: XSD Overview Univ. of the Aegean Financial and Management Engineering Dpt. Petros KAVASSALIS. What you will learn in this course.
E N D
Enterprise IT[Πληροφοριακές Τεχνολογίες της Επιχείρησης]Lecture 6-9: XSD OverviewUniv. of the Aegean Financial and Management Engineering Dpt Petros KAVASSALIS
What you will learn in this course • A set offundamentalconceptsfor understanding basic Enterprise Information Technologies • Enterprise Software Applications • Enterprise Architecture Integration (EAI) • Best practices and techniques for building and migrating to a service-oriented enterprise • Strategies for integrating applications using standard technologies • XML • Web Services • Familiarization with concepts such as: • Interoperability • e-business • e-government 2.0
Communication tools • e-mail: pkavassalis@atlantis-group.gr • Course web site: see FME web site
Students evaluation • Class Participation (20%) + • Assignments (20%) + • Final Exam (650%)
XSD in a nutshell • XML: XML Schema Definition Language • XML Working Group at W3C (please visit!) • Used for the definition of XML tags and structure • … the content and the structure of a class of XML documents • Schemas provide capabilities for expressing XML documents (the “logical structure” of the XML document • Support for metadata characteristics • Relationships • Cardinality • Valid Values • Data Types • XML documents without a referenced schema cannot be “validated” • If validated, the XML document has a valid construction… • Note: “Simple”, “short” XML documents do not necessarily require the use of an XSD scheme
XSD: components • Schema components = building blocks • Elements declarations • Attribute declarations • Simple Type definitions • Complex Type definitions • Notifications • etc…
XSD: architecture (1) <?xml version=“1.0” encoding=“UTF-8”?> <xsd:schema> NAMESPACE BODY </xsd/schema> Root element
XSD: architecture (2) J. Bean (2003)
XSD: Global and Local Elements • Global Elements: Available to be used in the rest of the schema • They are declared at the top level of the schema (BODY) • This declaration determines how the element will look like • They are “referenced” each time we want to use somewhere in the schema • Local Elements: Elements “on the spot” • They may not be used elsewhere in the schema • Their names are “locally” unique, i.e. unique only in the context in which they appear
XSD: Simple Types Elements with a built-in Type Custom Simple Types <xsd:simpleType name=“kapaType”> <xsd:restriction base=“xsd:datatype”> <xsd:pattern value=“pattern”/> </xsd:restriction> </xsd:simpleType> xml <kapa>data</kapa> • <xsd:element name=“label” type=“xsd:datatype”/> • xml • <label>data</label> • <xsd:element name=“weight” type=“xsd:string”/> • xml • <weight>200 kg</weight>
XSD: Simple TypesExample • <xsd:element name="car" type="carType"/><xsd:simpleType name="carType"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Audi"/> <xsd:enumeration value="Golf"/> <xsd:enumeration value="BMW"/> </xsd:restriction></xsd:simpleType>
XSD: built-in DataTypes and limitations for Simple Types • Data and Time Types (built-in) • Number Types (built-in) • Other built-in Types • Locate them • Acceptable Values foe simple Types • Patterns for simple Types • Range of Acceptable Values for simple Types • Length Limits for simple Types • Number’s Digits Length for simple Types • List Types • Element’s Content: pre-definition
XSD: Restrictions/Facets for Datatypes • http://www.w3schools.com/Schema/schema_elements_ref.asp • Restrictions/Facets for Datatypes
XSD: Complex Types • Simple Types • Complex Types • <xsd:simpleType name=“kapaType”> <xsd:restriction base=“xsd:datatype”> <xsd:pattern value=“pattern”/> </xsd:restriction> </xsd:simpleType> • xml • <kapa>data</kapa> • <xsd:complexType name=“kapaType”> <xsd:sequence> <xsd:element name=“lamda” type=”lamdaType”/> </xsd:sequence> </xsd:complexType
XSD: Complex TypesExplicitly naming the xml element (restricted) • xml <employee> <firstname>John</firstname> <lastname>Smith</lastname> </employee> • xsd <xsd:element name="employee"> <xsd:complexType> <xsd:sequence> <xsd:element name="firstname" type="xsd:string"/> <xsd:element name="lastname" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element>
XSD: Complex TypesSeveral elements can refer to a complex type • xml <employee> <firstname>John</firstname> <lastname>Smith</lastname> </employee> • xsd <xsd:element name="employee" type="personinfo"/><xsd:complexType name="personinfo"> <xs:dsequence> <xsd:element name="firstname" type="xsd:string"/> <xsd:element name="lastname" type="xsd:string"/> </xsd:sequence></xsd:complexType>
XSD: Complex TypesExtend a complex element • <xsd:element name="employee" type="fullpersoninfo"/> • <xsd:complexType name="personinfo"> <xsd:sequence> <xsd:element name="firstname" type="xsd:string"/> <xsd:element name="lastname" type="xsd:string"/> </xsd:sequence></xsd:complexType> • <xsd:complexType name="fullpersoninfo"> <xsd:copmlexContent> <xsd:extension base="personinfo"> <xsd:sequence> <xsd:element name="address" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="country" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent></xsd:complexType>
XSD: Complex TypesXSD Elements • http://www.w3schools.com/Schema/schema_elements_ref.asp • XSD Elements
XSD: Complex TypesChoice, Order and Groups • Set of choices • Elements appearing with no order • Max-Min Occurs • Groups of elements • Referencing a named group • How many elements? • XSD Attributes • xml • <lastnamelang="EN">Smith</lastname> • xsd • <xsd:attribute name="lang" type="xsd:string"/>
XSD: Complex TypesEmpty Elements • Empty Elements • xml • <product prodid="1345" /> • xsd • <xsd:element name="product"> <xsd:complexType> <xsd:attribute name="prodid" type="xsd:positiveInteger"/> </xsd:complexType></xsd:element> • xsd (2) • <xsd:element name="product" type="prodtype"/>4<xsd:complexType name="prodtype"> <xsd:attribute name="prodid" type="xsd:positiveInteger"/></xsd:complexType>
XSD: Complex TypesElements with Mixed Content Text-Only Elements (text, attributes) Mixed Elements xml <letter> Dear Mr.<name>John Smith</name>. Your order <orderid>1032</orderid> will be shipped on <shipdate>2001-07-13</shipdate>.</letter> xsd <xsd:element name="letter" type="lettertype"/><xsd:complexType name="lettertype" mixed="true"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="orderid" type="xsd:positiveInteger"/> <xsd:element name="shipdate" type="xsd:date"/> </xsd:sequence></xsd:complexType> • <xsd:element name="somename"> <xsd:complexType <xsd:simpleContent> <xsd:extension base="basetype"> .... .... </xsd:extension> </xsd:simpleContent> </xsd:complexType></xsd:element>
XSD: Complex TypesMore • <any> • <anyAttribute> • Substitution
XSD: Simple & Complex Types • All in One • http://www.codeguru.com/java/article.php/c13529(*) • http://www.learn-xml-schema-tutorial.com/
XSD: Complex TypesExamples • http://www.w3schools.com/Schema/schema_example.asp • http://www2.it.lut.fi/kurssit/08-09/CT30A2900/Lectures/Examples/An XML schema example.pdf
[References] • E. Castro, 2001, XML for the World Wide Web, Peachpit Press • Chapters 5, 6, 7, 8, 9 • J. Bean, 2003, XML for Data Architects, Morgan Kaufmann Pub. • Chapter 4