ITR3 lecture 3: Namespaces, XML Schema & XSL Thomas Krichel 2002-09-10.

Slides:



Advertisements
Similar presentations
XML III. Learning Objectives Formatting XML Documents: Overview Using Cascading Style Sheets to format XML documents Using XSL to format XML documents.
Advertisements

What is XML? a meta language that allows you to create and format your own document markups a method for putting structured data into a text file; these.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
1 Web Data Management XML Schema. 2 In this lecture XML Schemas Elements v. Types Regular expressions Expressive power Resources W3C Draft:
An Introduction to XML Based on the W3C XML Recommendations.
XSL XSLT and XPath 11-Apr-17.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XML Unit 6 October 31. XML, review XML is used to markup data Used to describe information Uses tags like HTML –But all tags are user-defined –Must be.
An Introduction to XML Schema CSCI 7818 by Ming Rutar.
XML Schemas Lecture 10, 07/10/02. Acknowledgements A great portion of this presentation has been borrowed from Roger Costello’s excellent presentation.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
DECO 3002 Advanced Technology Integrated Design Computing Studio Tutorial 6 – XML Schema School of Architecture, Design Science and Planning Faculty of.
ΑΝΑΠΑΡΑΣΤΑΣΗ ΓΝΩΣΗΣ ΣΤΟΝ ΠΑΓΚΟΣΜΙΟ ΙΣΤΟ XML Schema
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
1 Copyright (c) [2002]. Roger L. Costello. All Rights Reserved. Using Extension Elements and Extension Functions with XSLT and XPath Roger L. Costello.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
Why XML ? Problems with HTML HTML design - HTML is intended for presentation of information as Web pages. - HTML contains a fixed set of markup tags. This.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Copyright © [2001]. Roger L. Costello. All Rights Reserved. 1 XML Schemas (Primer)
XML CPSC 315 – Programming Studio Fall 2008 Project 3, Lecture 1.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
Extensible Markup and Beyond
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter X IXXXXXXXXXX XXXXXX.
Lecture 11 XSL Transformations (part 1: Introduction)
1 XML An Overview Roger Debreceny University of Hawai`i Skip White University of Delaware XBRL Workshop, August 2006.
New Perspectives on XML, 2nd Edition
Waqas Anwar Next SlidePrevious Slide. Waqas Anwar Next SlidePrevious Slide XML XML stands for EXtensible Markup Language.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
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.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
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
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
1 Copyright (c) [2000]. Roger L. Costello. All Rights Reserved. Using XSLT and XPath to Transform XML Documents Roger L. Costello XML Technologies.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Tutorial 2: XML Working with Namespaces. 2 Name Collision This figure shows two documents each with a Name element.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
Unit 4 Representing Web Data: XML
XML QUESTIONS AND ANSWERS
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
Database Processing with XML
Chapter 7 Representing Web Data: XML
Chapter X IXXXXXXXXXXXXXXXX.
More XML XML schema, XPATH, XSLT
Presentation transcript:

ITR3 lecture 3: Namespaces, XML Schema & XSL Thomas Krichel

Gee…. Birdseye view only, have a look at what these things do. If there is interest, I can teach some more in a separate course. Structure –Some XML related standards –Namespaces –XML Schema –XSL

Literature Castro, Elizabeth (2001). XML for the World Wide Web: Visual QuickStart Guide. Peachpit Press. Duckett, Jon et al. (2001). Professional XML Schemas. Wrox Press (recommended) Kay, Michael (2001). XSLT (2nd ed.). Wrox Press.

XHTML This is HTML redefined so that it becomes well-formed XML Examples –Case-sensitive elements – replaced by Verdict: pain without gain

Resource Description Framework (RDF) A standard issued by the W3C. A framework to encode meaning to make it computer processable. Uses the approach of a directed graph. Generalizes an object / property / value approach –Value may be another object. –Objects are URI identified by a URI. –Properties may be identified with a URI A paper on RDF available at RDF XML syntax is defined but currently being reworked. Verdict: very costly to implement.

Cascading style sheets (CSS) a non-XML way of writing stylesheets that can be applied to both XML and HTML. Widely supported by browsers. Written as a sequence of rules. Example compositionyear, recordingyear { color: red; font-family: sans-serif } Verdict: not flexible

XPath and XPointer are non-XML syntaxes referring to parts of an XML document, specific –Ranges –points –sets of XML document. There are used in other XML related standards, in particular, in XSL will be covered as part of XSL. Verdict: useful

XLinks is an XML syntax to link XML documents. They go way beyond the conventional linking capabilities of HTML, but there is no obvious way for the browser to represent them. Verdict: nonsense

Document Object Model DOM “a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The Document Object Model provides a standard set of objects for representing HTML and XML documents, a standard model of how these objects can be combined, and a standard interface for accessing and manipulating them.” Now at ''Level 3''. Works by building a tree out of a document. Verdict: exxxtremly complicated

Simple API for XML (SAX) SAX is an event-based paring model. It reports parsing events (such as the start and end of elements) directly to the application through callbacks Does not usually build an internal tree. A lot less resource-intensive, – when the document is large – when the task is simple. Verdict: thumbs up!

XML Information Sets best understood through an example. Consider two XML snippets. Snippet 1 Margarete Krichel Snippet 2 Margarete Krichel Are they the same?

XML Namespaces Allow to make XML element names and attribute name globally unique by associating them with a particular URI, usually a URL. The globally unique name is called the qualified name or qname, for short. The name without the namespace URI called the local name. This is done through a namespaces declaration, and a prefix. The namespace declaration associates a short string, called a prefix with the namespace. The qualified name can then be written as prefix:localname

Namespace syntax … element is the element name prefix is the prefix URI is a URI, often a URL, actually. [ ] indicate that it is optional. If the prefix is missing it means that all elements that have no namespace prefix belong, by default to the declared namespace. Namespace declaration remains local to the children of element.

Avoiding cerebral indigestion related to namespaces Expect nothing if you retrieve the namespace URI, when it is a URL. Prefixes can be any short string. Some prefixes are customary, like xsi for Default attributes only apply to elements not attributes. Attributes belong to the namespace of their elements, unless it has an explicit prefix.

XML Schemas (Primer) (Structures) (Datatypes)

What is XML Schema? XML Schema is vocabulary for expressing constraints for the validity of an XML document. A piece of XML is valid if it satisfies the constraints expressed in another XML file, the schema file. The idea is to check if the XML file is fit for a certain purpose.

Example To be valid, this XML snippet must meet all the following constraints: 1. The location must be comprised of a latitude, followed by a longitude, followed by an indication of the uncertainty of the lat/lon measurements. 2. The latitude must be a decimal with a value between -90 to The longitude must be a decimal with a value between -180 to For both latitude and longitude the number of digits to the right of the decimal point must be exactly six digits. 5. The value of uncertainty must be a non-negative integer 6. The uncertainty units must be either meters or feet.

Validating your data check that the latitude is between -90 and +90 -check that the longitude is between -180 and check that the fraction digits is 6 … Etc.. XML instance XML Schema validator Data is ok! XML Schema file software

History of Schema Once upon a time, there was SGML SGML has a “schema” language called a DTD. It is crap –Different syntax then SGML –Main focus on presence and absence of elements –Very limited capabilties to check contents of elements (datatypes)

XML Schemas can constrain the structure of instance documents –"this element contains these elements, which contains these other elements“, etc the datatype of each element/attribute –"this element shall hold an integer with the range 0 to 12,000"

Highlights of XML Schemas 44 built-in datatypes Can create your own datatypes by extending or restricting existing datatypes Written in the same syntax as instance documents Can express sets, i.e., can define the child elements to occur in any order Can specify element content as being unique (keys on content) and uniqueness within a region Can define multiple elements with the same name but different content Can define elements with nil content Can define substitutable elements

important schema concepts simple types: types that can not have child elements –elements that only have text contents and no attributes –attributes complex type: type of anything that can have child attributes

important schema concepts global declarations are direct children of the root schema element. They are visible everywhere. all local declarations are local and are limited in scope to the element that they appear within

important schema concepts Value space. The range of values that the type can take Lexical space. The range litterals that represent the value Set of facets. The defining properties of a type. –Fundamental facets include equality, order, bounds, cardinality, numeric/non-numeric –Constraining facets include ranges for numbers, string lengths, or a regular expressions

Namespaces XML Schema file mixes vocabulary from the XML Schema language with own vocabulary to be created. Has to keep both separate using namespaces. Namespaces associate a URI with names.

element complexType schema sequence string integer boolean BookStore Book Title Author Date ISBN Publisher (targetNamespace) This is the vocabulary that XML Schemas provide to define your new vocabulary This is the vocabulary for our book store xml description.

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> BookStore.xsd (see example01) xsd = Xml-Schema Definition (explanations on succeeding pages)

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified">

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> All XML Schemas have "schema" as the root element.

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> The elements and datatypes that are used to construct schemas - schema - element - complexType - sequence - string come from the namespace

element complexType schema sequence XMLSchema Namespace string integer boolean

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> Says that the elements defined by this schema - BookStore - Book - Title - Author - Date - ISBN - Publisher are to go in this namespace

BookStore Book Title Author Date ISBN Publisher (targetNamespace) Book Namespace (targetNamespace)

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> This is referencing a Book element declaration. The Book in what namespace? The default namespace is which is the targetNamespace!

<xsd:schema xmlns:xsd=" targetNamespace=" xmlns=" elementFormDefault="qualified"> This is a directive to any instance documents which conform to this schema: Any elements that are defined in this schema must be namespace-qualified when used in instance documents.

Referencing a schema in an XML instance document <BookStore xmlns =" xmlns:xsi=" xsi:schemaLocation=" BookStore.xsd"> My Life and Times Paul McCartney July, McMillin Publishing First, using a default namespace declaration, tell the schema-validator that all of the elements used in this instance document come from the namespace. 2. Second, with schemaLocation tell the schema-validator that the namespace is defined by BookStore.xsd (i.e., schemaLocation contains a pair of values). 3. Third, tell the schema-validator that the schemaLocation attribute we are using is the one in the XML Schema-instance namespace

schemaLocation type noNamespaceSchemaLocation XMLSchema-instance Namespace nil

Referencing a schema in an XML instance document BookStore.xml BookStore.xsd targetNamespace=" schemaLocation=" BookStore.xsd" - defines elements in namespace - uses elements from namespace A schema defines a new vocabulary. Instance documents use that new vocabulary.

Note multiple levels of checking BookStore.xmlBookStore.xsd XMLSchema.xsd (schema-for-schemas) Validate that the xml document conforms to the rules described in BookStore.xsd Validate that BookStore.xsd is a valid schema document, i.e., it conforms to the rules described in the schema-for-schemas

Using XSLT and XPath

XSL transforms XML XSL may be used to generate either HTML, XML, or text XSL Processor XSL XML HTML (or XML or text)

Doing it using Internet Explorer First, download the latest version of Internet Explorer (at this time it is 6.0) Write an XSL stylesheet stylish.xsl Write an XML file, and refer to the xsl stylesheet with a processing instruction Note: this does not work with other browsers!

XML tree XSL has a model of XML as a tree. XSL tree model is similar to the DOM model. As the processor does its job it looks at elements of the input tree and transforms them to the output tree. The processor only writes the file to the tree at the end. End points in the tree are called “nodes”.

in the general section we examine how XSL looks at an XML document. In fact it builds a tree. and then we look at a very simple way to look at what the stylesheet does. After that we have Roger showing us the details.

Seven types of nodes root node: contains all the elements in the document. Not to be confused with the document element of XML. element node: contains an element text node: contain an as-large-as-possible area of text. attribute node: contains attribute name and value comment node: contains a comment processing instruction (p-i) node namespace node: each element node has one namespace node for every namespace declaration

properties of nodes: name This is empty for the root, text and comment nodes. for elments and attribute node, it is the name as it appears in the xml file, expanded by namespace declarations. for p-i nodes, it is the target for a namespace node, it is the prefix

properties of nodes: string value for text nodes: the text for comment nodes: the text of the comment for p-i nodes: the data part of the p-i. for an attribute node: the value of the attribute for a root node: the concatenation of all the string values of all element and text children. for a namespace node: the URI of the namespace

properties of nodes: base URI for all nodes: the URI of the XML source document where the node has been found Only of interest for elements and p-i nodes for the root node: the URI of the document for attribute, text and comment nodes: the base URI of its parent node

properties of nodes: children for element nodes: all the element nodes, text nodes, p-i nodes and comment nodes between its start and end tags. for root nodes: all the element nodes, text nodes, p-i nodes and comment nodes that are not children of some other node.

parent node for all nodes except root nodes: the parent of the node. attribute nodes and namespace nodes have an element node as parent node, but are not considered to be its child.

property of nodes: attribute element: one to many attributes that the element has other nodes: empty Now we look at what XSL does

Different formats… is the default used for everything else. Final formatting may be up to formatting objects, anyway. Your stylesheet processor may have more formats, but they will be vendor-specific.

templates set rules do some stuff This is a rule that says, if you find a node that matches the expression expression, then go ahead and do some stuff. It is called a template. The fact that a rule is written down down does not imply that it is applied.

applying templates says: apply all template rules on the current node and on all its child nodes.

Default, built-in rules for the nodes root: on all children element: to the current node and all its children attribute: copy the value as text to the output text: copy the text to the output comment, p-i, namespace: do nothing

HTML Generation We will first use XSL to generate HTML documents When generating HTML, XSL should be viewed as a tool to enhance HTML documents. –That is, the HTML documents may be enhanced by extracting data out of XML documents –XSL provides elements (tags) for extracting the XML data, thus allowing us to enhance HTML documents with data from an XML document

Enhancing HTML Documents with XML Data XML Document HTML Document (with embedded XSL elements) XSL element XML data XSL Processor XML data

Enhancing HTML Documents with the Following XML Data Jeff lightgrey FitnessCenter.xml

Embed HTML Document in an XSL Template Welcome Welcome! FitnessCenter.xsl (see html-example01)

Note The HTML is embedded within an XSL template, which is an XML document. T he HTML must be well formed. We are able to add XSL elements to the HTML, allowing us to extract data out of XML documents. Let's customize the HTML welcome page by putting in the member's name. This is achieved by extracting the name from the XML document. We use an XSL element to do this.

Extracting the Member Name <xsl:stylesheet xmlns:xsl=" version="1.0"> Welcome Welcome ! (see html-example02)

Extracting a Value from & Navigating the XML Document Extracting values: –use the XSL element Navigating: –The slash ("/") indicates parent/child relationship –A slash at the beginning of the path indicates that it is an absolute path, starting from the top of the XML document /FitnessCenter/Member/Name "Start from the top of the XML document, go to the FitnessCenter element, from there go to the Member element, and from there go to the Name element."

Document / PI Element FitnessCenter Element Member Element Name Element Phone Element Phone Element FavoriteColor Text Jeff Text Text Text lightgrey

Thank you for your attention!