CS 157B: Database Management Systems II February 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.

Slides:



Advertisements
Similar presentations
XML Schema Heewon Lee. Contents 1. Introduction 2. Concepts 3. Example 4. Conclusion.
Advertisements

XML: Extensible Markup Language
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
XML 6.5 XML Schema (XSD) 6. What is XML Schema? The origin of schema  XML Schema documents are used to define and validate the content and structure.
1 XML DTD & XML Schema Monica Farrow G30
JAXB Java Architecture for XML Binding Andy Fanton Khalid AlBayat.
XML Schema Definition Language
Fonts and colors Times New Roman “quotes” Trebuchet "quotes" yellow blue pink green violet.
1 Week5 – Schema Why Schema? Schemas vs. DTDs Introduction – W3C vs. Microsoft XDR Schema, How To? Element Types – Simple vs. Complex Attributes Restrictions/Facets.
XML Schemas. “Schemas” is a general term--DTDs are a form of XML schemas –According to the dictionary, a schema is “a structured framework or plan” When.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
29-Jun-15 JAXB Java Architecture for XML Binding.
JAXB Java Architecture for XML Bindings. What is JAXB? JAXB defines the behavior of a standard set of tools and interfaces that automatically generate.
XML Schema Describing the structure of XML documents. A very brief introduction 1XML Schema.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Web Services with Apache CXF Part 2: JAXB and WSDL to Java Robert Thornton.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
CS 174: Web Programming April 16 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
AIXM Viewer Implementation Presentation to AIXM Users’ Conference, Federal Aviation Administration, Washington D.C., Feb 27-March 1, By: Mark Austin,
17 Apr 2002 XML Schema Andy Clark. What is it? A grammar definition language – Like DTDs but better Uses XML syntax – Defined by W3C Primary features.
CS 157B: Database Management Systems II February 27 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
Object-oriented tools for XML Schema JAXB (Java Architecture for XML Binding) –object connectivity for XML documents HyperJAXB –relational persistence.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
XML Schema Vinod Kumar Kayartaya. What is XML Schema?  XML Schema is an XML based alternative to DTD  An XML schema describes the structure of an XML.
Maziar Sanaii Ashtiani – SCT – EMU, Fall 2011/12.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
CSE4500 Information Retrieval Systems XML Schema – Part 1.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
CS 157B: Database Management Systems II May 8 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
1 Dr Alexiei Dingli XML Technologies X-Schema. 2 XML-based alternative to DTD Describes the structure of an XML document Also referred to as XML Schema.
Session IV Chapter 9 – XML Schemas
CS 157B: Database Management Systems II February 6 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
New Perspectives on XML, 2nd Edition
 XML DTD and XML Schema Discussion Sessions 1A and 1B Session 2.
Waqas Anwar Next SlidePrevious Slide. Waqas Anwar Next SlidePrevious Slide XML XML stands for EXtensible Markup Language.
CS 157B: Database Management Systems II February 25 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
Sheet 1XML Technology in E-Commerce 2001Lecture 2 XML Technology in E-Commerce Lecture 2 Logical and Physical Structure, Validity, DTD, XML Schema.
XML 2nd EDITION Tutorial 4 Working With Schemas. XP Schemas A schema is an XML document that defines the content and structure of one or more XML documents.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
XML Schema. Why Validate XML? XML documents can generally have any structure XML grammars define specific document structures Validation is the act of.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
CS 157B: Database Management Systems II February 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
EGEE is a project funded by the European Union under contract IST XML Schema 3 – 4 June
CMPE 226 Database Systems November 4 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming November 4 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
CS 157B: Database Management Systems II February 13 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Deriving Complex Types In XML Schema By: Roy Navon.
Lecture 0 W3C XML Schema. Topics Status Motivation Simple type vs. complex type.
XML Schema – Simple Type Web site:
CMPE 226 Database Systems November 4 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
XSD 2015, Fall Pusan National University HyungGyu Ryoo 1.
CITA 330 Section 4 XML Schema. XML Schema (XSD) An alternative industry standard for defining XML dialects More expressive than DTD Using XML syntax Promoting.
XML Schemas Dr. Awad Khalil Computer Science Department AUC.
Session III Chapter 10 – Defining Simple Types
XML QUESTIONS AND ANSWERS
CMP 051 XML Introduction Session IV
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
CS 174: Server-Side Web Programming February 12 Class Meeting
Design and Implementation of Software for the Web
CMP 051 XML Introduction Session IV Chapter 10 – Defining Simple Types
JAXB Overview Vladimir Gapeyev.
Presentation transcript:

CS 157B: Database Management Systems II February 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 2 XML Schema  XML Schema Definition (XSD)  Specify the structure of XML data. Application-specific. Replacement for DTD.  An XML document is well-formed if it has correct XML syntax.   An XML document is valid if its contents conform to its schema. The schema specifies what elements and attributes a valid document must have, and in what order. The schema specifies the data type and format of the content. _

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 3 XML Schema Types  Simple type An XML element with only text content. No attributes and no child elements.  Complex types Four complex types: Complex typeAttributesChildrenText content Text onlyyes- Element onlyyes - Empty elementyes-- Mixed contentyes

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 4 Simple Type Definition  Example:  Some basic types: xs:string xs:integer xs:decimal xs:boolean  false or true (or: 0 or 1) xs:date  format YYYY-MM-DD xs:time  format hh:mm:ss xs:dateTime  format YYYY-MM-ddThh:mm:ss xs:anyURI Note the T

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 5 Simple Type Definition  Predefined value Example: If the element is present and has content, the content must match the predefined value. If the element is present but empty, it gets the predefined value. If the element is not present, it has no value.  Default value Example: If the element is empty or not present, it gets the default value. If the element is present and has content, the content that’s there is used as the value. <xs:element name="age" type="xs:integer" fixed="25"/> <xs:element name="age" type="xs:integer" default="25"/>

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 6 Derived Simple Types  Derive a custom simple type from a base type. Example:  This is an anonymous custom type. The type itself has no name. It applies only to the element (birthday) for which it is defined. _ <xs:element name="birthday"

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 7 Derived Simple Types  Named custom type. The type has a name. Multiple elements can refer to the type by name. Example:

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 8 Derived Simple Types  A set of acceptable content values. Example:

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 9 Derived Simple Types  A regular expression pattern. Example: Perl-style regular expression.

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 10 Derived Simple Types  A union type. Example:

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 11 Derived Simple Types  A list type. Example: Therefore, in the XML document, the “holidays” element can have a list of date values:

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 12 Sample XML Document <catalog xmlns:xsi=" xsi:noNamespaceSchemaLocation="catalog.xsd"> Design XML Schemas Using UML Ayesha Malik Design service-oriented architecture frameworks with J2EE technology Naveen Balani Advance DAO Programming Sean Sullivan Schema reference XML document adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 13 Sample XML Schema: catalog.xsd... XML schema adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 14 Sample XML Schema: catalog.xsd... <xs:element ref="article" minOccurs="0" maxOccurs="unbounded"/>...

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 15 Sample XML Schema: catalog.xsd... <xs:element ref="journal" minOccurs="0" maxOccurs="unbounded"/>

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 16 Complex Types  Four complex types: Complex typeAttributesChildrenText content Text onlyyes- Element onlyyes - Empty elementyes-- Mixed contentyes

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 17 Complex Types: Element Only  Attributes and child elements, no text content. Example: imposes an order on child elements. for child elements in any order. elements come last. _

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 18 Complex Types: Element Only  Choice of child elements Example: Either a social security number, or a username followed by a password.

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 19 Complex Types: Text Only  Attributes and text content, no child elements. Example:  In this example, an element of type “year_type” must have content that is a positive integer. It must also have an “era” attribute whose value is a string. Use instead of to add restrictions (such as maximum string length) to the base type. _

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 20 Complex Types: Empty Element  Attributes only, no text content and no child elements. Example:

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 21 Complex Types: Mixed Content  Attributes, child elements, and text content. Example: The elements are interspersed among the text content. Instead of, you can also use or. _...

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 22 Attributes  Attributes are simple type elements. Example:  Attributes are optional by default. Add use="required" to the attribute definition to make the attribute mandatory. Add use="prohibited" to prohibit the attribute. _

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 23 Validating XML Documents  Install NetBeans XML tools plugins: Schema editor netbeans netbeans Query window  Validate an XML document using Java’s DOM and SAX parsers. _ Demos

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 24 Object-XML Mapping  JAXB 2.0 package. Automatic object-XML mapping. Object bindings: One Java object per XML element. Similar to object-relational mapping with Hibernate.  Use the xjc compiler to generate Java classes for complex types in the XML schema. Complete with Java annotations. Requires an XML schema.  At run time: Marshalling  Generate XML elements from a Java object tree. Unmarshalling  Generate a Java object tree from a XML elements.

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 25 Complete XML Schema <xs:element ref="article" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="journal" minOccurs="0" maxOccurs="unbounded"/> XML schema adapted from the book Pro XML Development with Java Technology, by Ajay Vohra and Deepak Vohra, Apress, 2006

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 26 xjc Compiler  Should be part of your standard Java installation.  Command line: is where you want the generated Java classes to go. (It’s the source directory for the Java compiler.) Example:  The xjc compiler generates Java classes for complex types in the XML schema. The classes will be properly annotated for XML mapping. _ xjc –d -p xjc -d src -p jaxbdemo.generated catalog.xsd

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 27 Unmarshalling an XML Document  Create an unmarshaller. Put the generated Java classes into package jaxbdemo.generated for this example.  Unmarshal the XML document. Get a Catalog object. Get the list of Journal objects. JAXBContext jaxbContext = JAXBContext.newInstance("jaxbdemo.generated"); Unmarshaller unMarshaller = jaxbContext.createUnmarshaller(); JAXBElement catalogElement = (JAXBElement ) unMarshaller.unmarshal(xmlDocument); CatalogType catalog = catalogElement.getValue(); List journalList = catalog.getJournal(); Demo

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 28 Marshalling an XML Document  Create a marshaller and an object factory. We'll use the Java classes in package jaxbdemo.generated for this example.  Create a Catalog and Journal objects. Get references to the lists of Journal and Article objects. Add the Journal object to the Journal list. JAXBContext jaxbContext = JAXBContext.newInstance("jaxbdemo.generated"); Marshaller marshaller = jaxbContext.createMarshaller(); ObjectFactory factory = new ObjectFactory(); CatalogType catalog = factory.createCatalogType(); List journalList = catalog.getJournal(); JournalType journal = factory.createJournalType(); List articleList = journal.getArticle(); journalList.add(journal); Demo

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 29 Marshalling an XML Document  Create an Article object. Add it to the Article list.  Marshal the Java objects to XML elements. Write the XML document to standard out. ArticleType article = factory.createArticleType(); article.setTitle("Service Oriented Architecture Frameworks"); article.setAuthor("Naveen Balani"); article.setLevel("Intermediate"); article.setDate("January-2004"); articleList.add(article); JAXBElement catalogElement = factory.createCatalog(catalog); marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE); marshaller.marshal(catalogElement, System.out);

Department of Computer Science Spring 2013: February 18 CS 157B: Database Management Systems II © R. Mak 30 Project #2  Due: Friday, March 1.  Experience: Writing XML schemas Validating XML documents Marshalling and unmarshalling XML data XQuery Altova XMLSpy tool  Download the Altova XMLSpy 2013 tool from: Evaluation good for 30 days. _