G52IWS: Extensible Markup Language (XML)

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
XML 6.3 DTD 6. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:  Elements.
SDPL 2003Notes 2: Document Instances and Grammars1 2.5 XML Schemas n A quick introduction to XML Schema –W3C Recommendation, May 2, 2001: »XML Schema Part.
Document Type Definitions
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
 2002 Prentice Hall, Inc. All rights reserved. ISQA 407 XML/WML Winter 2002 Dr. Sergio Davalos.
XML Schemas and Namespaces Lecture 11, 07/10/02. BookStore.dtd.
Sunday, June 28, 2015 Abdelali ZAHI : FALL 2003 : XML Schemas XML Schemas Presented By : Abdelali ZAHI Instructor : Dr H.Haddouti.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Tutorial 11 Creating XML Document
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
Unit 4 – XML Schema XML - Level I Basic.
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.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 1 Lecturer.
1 XML Schemas. 2 Useful Links Schema tutorial links:
Dr. Azeddine Chikh IS446: Internet Software Development.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Schemas Ellen Pearlman Eileen Mullin Programming the Web Using XML.
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.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
1 © Netskills Quality Internet Training, University of Newcastle Introducing XML © Netskills, Quality Internet Training University.
Introduction to XML. What is XML? Extensible Markup Language XML Easier-to-use subset of SGML (Standard Generalized Markup Language) XML is a.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
 2002 Prentice Hall, Inc. All rights reserved. Chapter 6 – Document Type Definition (DTD) Outline 6.1Introduction 6.2Parsers, Well-formed and Valid XML.
Of 33 lecture 3: xml and xml schema. of 33 XML, RDF, RDF Schema overview XML – simple introduction and XML Schema RDF – basics, language RDF Schema –
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
XML Documents Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University Elements Attributes Comments PI Document.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
An Introduction to XML Sandeep Bhattaram
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 5 XML Schema (Based on Møller and Schwartzbach,
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
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
225 City Avenue, Suite 106 Bala Cynwyd, PA , phone , fax presents… XML Syntax v2.0.
Introduction to XML Schema John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel: (x2073)
Well Formed XML The basics. A Simple XML Document Smith Alice.
XML Schema Definition (XSD). Definition of a Schema It is a model for describing the structure and content of data The XML Schema was developed as a content.
XML Validation. a simple element containing text attribute; attributes provide additional information about an element and consist of a name value pair;
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
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.
XML SCHEMA 1 CH 20. Objective 2 What’s wrong with DTDs? What is a schema? The W3C XML Schema Language Hello schemas Complex types Simple types Deriving.
Web Services: Principles & Technology Slide 3.1 Chapter 3 Brief Overview of XML COMP 4302/6302.
4 Copyright © 2004, Oracle. All rights reserved. Validating XML by Using XML Schema.
eXtensible Markup Language
Unit 4 Representing Web Data: XML
Extensible Markup Language XML
XML QUESTIONS AND ANSWERS
Extensible Markup Language XML
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
XML Technologies and Related Applications
Session III Chapter 6 – Creating DTDs
Chapter 7 Representing Web Data: XML
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
ece 720 intelligent web: ontology and beyond
XML Schema Primer Seong Jong Choi Multimedia Lab.
Session II Chapter 6 – Creating DTDs
CH 20 XML Schema.
Allyson Falkner Spokane County ISD
New Perspectives on XML
Presentation transcript:

G52IWS: Extensible Markup Language (XML) Chris Greenhalgh

Contents What is XML XML standards XML Syntax DTDs XML Schema See “Developing Java Web Services” chapter 8, first part and G51WPS notes on XML; see W3C standards

What is XML Text-based language for structured data encoding Tree-structured Common abstract syntax any XML document can be read by a common parser DTDs or XML-Schema define particular application-specific constraints E.g. new tags, allowed structures & datatypes

XML standards Created in 1996 Derived from SGML markup language Managed by the W3C XML (www.w3c.org) group(s) since 1998 http://www.w3.org/XML/Core/#Publications inc: Extensible Markup Language (XML) 1.0 (Fourth Edition) http://www.w3.org/XML/Schema#dev inc: XML Schema Part 0: Primer http://www.w3.org/XML/Query/#specs inc: XML Path Language (XPath) 2.0 …

XML Example (no DTD) <?xml version="1.0" ?> <Friends> <Person> <Name>Jane Doe</Name> <Age>21</Age> <Body> <Weight Unit="lbs">126</Weight> <Height Unit="inches">62</Height> </Body> <Trust trusted="yes"/> </Person> <Name>John Doe</Name> <Age>26</Age> <Trust trusted="no"/> </Friends>

XML document structure Prolog Document type declaration Optional Includes element declarations Root element With nested elements With optional attributes With optional text content (incl. CDATA sections) Interleaved with optional comments and processing instructions

XML Syntax Contents Prolog Root Processing instructions Comments Names Tags Elements Content and CDATA sections Attributes Entities Namespaces

Prolog Every XML document starts with prolog, e.g. <?xml version="1.0" ?> <?xml version="1.0" encoding="ISO-8859-1" ?> Known start allows multi-byte and byte-order encodings to be identified Allows specific encoding to be specified Defaults to Unicode (UTF-8 if single byte)

Root Every XML document has exactly one “top”-level or root element, e.g. <?xml version="1.0" ?> <Friends> … </Friends> But not e.g. <?xml version="1.0" ?> <Friends> … </Friends> <Friends> … </Friends>

Processing instructions Provide information for XML processing application(s) Are of the form: <?target instructions?> Includes the document prolog: <?xml version="1.0" ?>

Comments Used for documentation Are of the form: <!-- some comment --> E.g.: <?xml version="1.0" ?> <!-- my friends --> <Friends> <!-- my first friend --> <Person> … </Person> </Friends>

Names No blanks spaces Must start with alphabetical letter (e.g. A-Z or a-z) or underscore (_) Can be followed by letters, digits (0-9), underscores (_), hyphens (-), periods (.) and colons (:) Colons are normally reserved for use with namespaces Case-sensitive E.g. “product” is different from “Product”

Tags Main building block of XML Start tag: <tagname optional-attributes> End tag: </tagname> Empty-element tag: <tagname optional-attributes/>

XML Example <?xml version="1.0" ?> Start tag without attributes <Friends> <Person> <Name>Jane Doe</Name> <Age>21</Age> <Body> <Weight Unit="lbs">126</Weight> <Height Unit="inches">62</Height> </Body> <Trust trusted="yes"/> </Person> <Name>John Doe</Name> <Age>26</Age> <Trust trusted="no"/> </Friends> Start tag without attributes Start tag with attributes Empty-element tag End tag

Elements Basic building block of XML Have form: Never overlap Start tag … matching end tag or Empty-element tag Never overlap Unlike SGML E.g. can’t have “<a>…<b>…</a>…</b>” But can be nested I.e. a tree, starting from the root element E.g. can have “<a>…<b>…</b>…</a>” Can contain textual content

Content and CDATA sections Within elements between start and end tags Plain text Whitespace optionally significant No ‘<‘ or ‘&’ Use entity references instead (“<&”) CDATA “escape” section can include any text unescaped except “]]>” e.g. <![CDATA[<hello>&asoa,osd>as<]]>

Attributes Set of key-value pairs associated with each element Defined in the start tag or empty-element tag never in the end tag Optional Each key must be unique within that element E.g. attribute key is “Unit” and value is “lbs”: <Weight Unit="lbs">126</Weight>

Entities Short-cuts/references to text Of the form: &entityname; E.g. < < > > & & " " &apos; ' More can be defined in the (optional) DTD

Namespaces Are contexts within which names are defined Prevent confusion between coincidental uses of the same names (for elements or attributes) Namespace is a URI Never actually resolved to a document Default namespace introduced by attribute xmlns="namespaceuri" Applies to that and all subsequent unqualified element names (NOT attribute names) Namespace prefix introduced by attribute xmlns:prefix="namespaceuri" Used explicitly as “prefix:name” No namespace is the same as the empty URI “” This is the top-level default namespace and default namespace for all attributes at any level

Namespace example Expanded names <?xml version="1.0" ?> <Friends xmlns="http://woo.foo/"> <Person xmlns:n2="http://wee.fee/"> <n2:Name>Jane Doe</n2:Name> <Age xmlns="http://wee.fee/">21</Age> <Weight Unit="lbs">126</Weight> <Height n2:Unit="inches">62</Height> </Person> </Friends> “http://woo.foo/”,”Friends” Default NS “http://woo.foo/” “http://woo.foo/”,”Person” “http://wee.fee/”,”Name” Default NS “http://wee.fee/” “http://wee.fee/”,”Age” “http://woo.foo/”,”Weight” (att.) “”,”Unit” (att.) “http://wee.fee/”,”Unit”

Document Type Definitions Use regular expressions to specify valid document structure Element nesting, required and optional attributes, default values May be included after prolog in document Or may be referenced from an external name or URL Relatively limited expressiveness, especially for attribute and text values See G51WPS notes

XML Schema More modern alternative to DTDs for specifying valid XML document structure and content See http://www.w3.org/XML/Schema#dev XML Schema Part 0: Primer XML Schema Part 1: Structures XML Schema Part 2: Datatypes

XML Schema An XML Schema definition is an XML document conforming to the XML Schema schema  Allows definition of simple types Without nested elements Including built-in types such as xsd:decimal, xsd:string complex types with nested elements and optional attributes Elements (which may be simple or complex) Attributes (which all have simple types)

XML Schema example 1 <?xml version="1.0"?> <schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://woo.foo/"> <xsd:element name="comment" type="xsd:string"/> </schema> Defines one element “http://woo.foo”,”comment” of simple type xsd:string, e.g. <?xml version="1.0"?> <comment xmlns="http://woo.foo/">this is a comment</comment>

XML Schema example 2 <?xml version="1.0"?> <schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://woo.foo/"> <xsd:simpleType name="Chocolate"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="dark"/> <xsd:enumeration value="milk"/> <xsd:enumeration value="white"/> </xsd:restriction> </xsd:simpleType> <xsd:element name="chocolate" type="Chocolate"/> </schema> Defines one element “http://woo.foo”,”chocolate” of new simple type “http://woo.foo”,”Chocolate”, which must be “dark”, “milk” or “white” <?xml version="1.0"?> <chocolate xmlns="http://woo.foo/">dark</chocolate>

XML Schema example 3 <?xml version="1.0"?> <schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://woo.foo/"> <xsd:complexType name=“ThreePiece"> <xsd:sequence> <xsd:element name="lead" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="bass" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="drums" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> <xsd:element name=“band" type="ThreePiece"/> </schema> Defines one element “http://woo.foo”,”band” of new complex type “http://woo.foo”,”ThreePiece”, with three mandatory child elements <?xml version="1.0"?> <band xmlns="http://woo.foo/"> <lead>Bill</lead> <bass>Bob</bass> <drums>Ben</drums> </band>

G52IWS XML 2007-10-10 XML Schema example 4 <?xml version="1.0"?> <schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://woo.foo/"> <xsd:complexType name=“WeightType"> <xsd:simpleContent> <xsd:extension base="xsd:double"> <xsd:attribute name="Units" type="xsd:string"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:element name="weight" type=“WeightType"/> </schema> Defines one element “http://woo.foo”,”weight” of new simple type “http://woo.foo”,”Chocolate”, which must be “dark”, “milk” or “white” <?xml version="1.0"?> <weight xmlns="http://woo.foo/" Units="kg">dark</chocolate>

XML Schema built-in data types string base64binary – Base64 encoded binary boolean – true or false decimal – integers double – 64 bit floating point float – 32 bit floating point anyUri – URI duration – duration dateTime- date & time … And various restrictions, e.g. minimum & maximum values, lengths

Complex type building blocks Element combinations: Sequence – in order given, specifiable count All – in any order, 0 or 1 of each Choice – one of Additional constructions Reusable groups of elements Reusable groups of attributes Substitution groups Alternative elements which may appear in a particular place

Summary XML XML Schema Common abstract syntax Hierarchical element tree, plus content and attributes XML Schema Specifies XML elements and allowed structure and content for XML document(s) Checked by “validating” parsers Used to formally specify WSDL, SOAP, etc. Can be used to generate schema-specific APIs E.g. Java API for XML Binding (JAXB) Typically more readable code than DOM or SAX