XML. Document Type Definitions XML Schema



Similar documents
Semistructured data and XML. Institutt for Informatikk INF Ahmet Soylu

Structured vs. unstructured data. Motivation for self describing data. Enter semistructured data. Databases are highly structured

Last Week. XML (extensible Markup Language) HTML Deficiencies. XML Advantages. Syntax of XML DHTML. Applets. Modifying DOM Event bubbling

Quiz! Database Indexes. Index. Quiz! Disc and main memory. Quiz! How costly is this operation (naive solution)?

XML: extensible Markup Language. Anabel Fraga

Introduction to XML. Data Integration. Structure in Data Representation. Yanlei Diao UMass Amherst Nov 15, 2007

DTD Tutorial. About the tutorial. Tutorial

XML Schema Definition Language (XSDL)

Structured vs. unstructured data. Semistructured data, XML, DTDs. Motivation for self-describing data

XML and Data Management

XEP-0337: Event Logging over XMPP

04 XML Schemas. Software Technology 2. MSc in Communication Sciences Program in Technologies for Human Communication Davide Eynard

Altova XMLSpy Tutorial

XML for Beginners. Ralf Schenkel. 1. XML the Snake Oil of the Internet age? 2. Basic XML Concepts 3. Defining XML Data Formats 4.

Standard Recommended Practice extensible Markup Language (XML) for the Interchange of Document Images and Related Metadata

E-Return Intermediary (ERI) User Registration and Services

Translating between XML and Relational Databases using XML Schema and Automed

[MS-FSDAP]: Forms Services Design and Activation Web Service Protocol

Designing EDIFACT message structures with XML schema

Extensible Markup Language (XML): Essentials for Climatologists

<xs:complextype name="trescdokumentu_typ">

RUT developers handbook 9.51 Introduction to XML and DOM, with applications in Matlab v. 2.0

1. Write the query of Exercise 6.19 using TRC and DRC: Find the names of all brokers who have made money in all accounts assigned to them.

XML Schema Versioning

+ <xs:element name="productsubtype" type="xs:string" minoccurs="0"/>

An XML Based Data Exchange Model for Power System Studies

Modernize your NonStop COBOL Applications with XML Thunder September 29, 2009 Mike Bonham, TIC Software John Russell, Canam Software

Data Integration through XML/XSLT. Presenter: Xin Gu

Chapter 2: Designing XML DTDs

Building Data Integrator Real-time Jobs and Calling Web Services

XML and Data Integration

XML for SAS Programmers

<xs:restriction base="xs:string">

How To Use Xml In A Web Browser (For A Web User)

Rule-Based Generation of XML DTDs from UML Class Diagrams

Web Services Technologies

keyon Luna SA Monitor Service Administration Guide 1 P a g e Version Autor Date Comment

DRAFT. Standard Definition. Extensible Event Stream. Christian W. Günther Fluxicon Process Laboratories

Specify the location of an HTML control stored in the application repository. See Using the XPath search method, page 2.

Kuali Financial System Interface Specification for Electronic Invoice Feed

Agency to System Infrastructure Provider Interface Specification

10CS73:Web Programming

COM_2006_023_02.xsd <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs=" elementformdefault="qualified">

OpenTravel Alliance XML Schema Design Best Practices

Exchanger XML Editor - Canonicalization and XML Digital Signatures

Modern Databases. Database Systems Lecture 18 Natasha Alechina

[MS-DVRD]: Device Registration Discovery Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

XML Schemas. Written in a language other than XML; so need a separate parser.

DocuSign Connect Guide

VIRTUAL LABORATORY: MULTI-STYLE CODE EDITOR

CHAPTER 9: DATAPORT AND XMLPORT CHANGES

Entity-Relationship Model. Purpose of E/R Model. Entity Sets

XSLT Mapping in SAP PI 7.1

i-scream The future is bright; the future is blue.

ATWD XML Web Service Handbook

Java and XML parsing. EH2745 Lecture #8 Spring

HTML, CSS, XML, and XSL

Common Data Format 3 Overview

Managing XML Documents Versions and Upgrades with XSLT

Balisage: The Markup Conference

LabVIEW Internet Toolkit User Guide

Advanced PDF workflows with ColdFusion

Adobe Cross Domain Policy File Specification Version 2.0

XML, XSLT and e-commerce

Grandstream XML Application Guide Three XML Applications

5.1 Radical Notation and Rational Exponents

<!--=========================================--> <!--=========================================-->

Real SQL Programming. Persistent Stored Modules (PSM) PL/SQL Embedded SQL

Languages for Data Integration of Semi- Structured Data II XML Schema, Dom/SAX. Recuperación de Información 2007 Lecture 3.

Extending the Linked Data API with RDFa

Relational Databases for Querying XML Documents: Limitations and Opportunities. Outline. Motivation and Problem Definition Querying XML using a RDBMS

Structured Data and Visualization. Structured Data. Programming Language Support. Programming Language Support. Programming Language Support

Schema XSD opisująca typy dokumentów obsługiwane w Systemie invooclip

Representation of E-documents in AIDA Project

Model-driven Rule-based Mediation in XML Data Exchange

Secure XML API Integration Guide - Periodic and Triggered add in

XIII. Service Oriented Computing. Laurea Triennale in Informatica Corso di Ingegneria del Software I A.A. 2006/2007 Andrea Polini

The New System of Accounts Message structure: Cash settlement balances derivatives (demt.smc )

SW : : Introduction to Web Services with IBM Rational Application Developer V6

Introduction to Ingeniux Forms Builder. 90 minute Course CMSFB-V6 P

Transcription:

XML Document Type Definitions XML Schema 1

Well-Formed and Valid XML Well-Formed XML allows you to invent your own tags. Valid XML conforms to a certain DTD. 2

Well-Formed XML Start the document with a declaration, surrounded by <?xml?>. Normal declaration is: <?xml version = 1.0 standalone = yes?> standalone = no DTD provided. Balance of document is a root tag surrounding nested tags. 3

Tags Tags are normally matched pairs, as <FOO> </FOO>. Unmatched tags also allowed, as <FOO/> Tags may be nested arbitrarily. XML tags are case-sensitive. 4

Example: Well-Formed XML Root tag <?xml version = 1.0 standalone = yes?> <BARS> <BAR><NAME>Joe s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> </BARS> Tags surrounding a BEER element A NAME subelement A BEER subelement 5

DTD Structure <!DOCTYPE <root tag> [ <!ELEMENT <name>(<components>)>... more elements... ]> 6

DTD Elements The description of an element consists of its name (tag), and a parenthesized description of any nested tags. Includes order of subtags and their multiplicity. Leaves (text elements) have #PCDATA (Parsed Character DATA ) in place of nested tags. 7

<!DOCTYPE BARS [ ]> Example: DTD <!ELEMENT BARS (BAR*)> <!ELEMENT BAR (NAME, BEER+)> <!ELEMENT NAME (#PCDATA)> <!ELEMENT BEER (NAME, PRICE)> <!ELEMENT PRICE (#PCDATA)> NAME and PRICE are text. A BARS object has zero or more BAR s nested within. A BAR has one NAME and one or more BEER subobjects. A BEER has a NAME and a PRICE. 8

Element Descriptions Subtags must appear in order shown. A tag may be followed by a symbol to indicate its multiplicity. * = zero or more. + = one or more.? = zero or one. Symbol can connect alternative sequences of tags. 9

Example: Element Description A name is an optional title (e.g., Prof. ), a first name, and a last name, in that order, or it is an IP address: <!ELEMENT NAME ( )> (TITLE?, FIRST, LAST) IPADDR 10

Use of DTD s 1. Set standalone = no. 2. Either: a) Include the DTD as a preamble of the XML document, or b) Follow DOCTYPE and the <root tag> by SYSTEM and a path to the file where the DTD can be found. 11

Example: (a) <?xml version = 1.0 standalone = no?> <!DOCTYPE BARS [ <!ELEMENT BARS (BAR*)> <!ELEMENT BAR (NAME, BEER+)> The DTD <!ELEMENT NAME (#PCDATA)> <!ELEMENT BEER (NAME, PRICE)> <!ELEMENT PRICE (#PCDATA)> The document ]> <BARS> <BAR><NAME>Joe s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> </BARS> 12

Example: (b) Assume the BARS DTD is in file bar.dtd. <?xml version = 1.0 standalone = no?> <!DOCTYPE BARS SYSTEM bar.dtd > <BARS> <BAR><NAME>Joe s Bar</NAME> <BEER><NAME>Bud</NAME> <PRICE>2.50</PRICE></BEER> <BEER><NAME>Miller</NAME> <PRICE>3.00</PRICE></BEER> </BAR> <BAR> </BARS> Get the DTD from the file bar.dtd 13

Attributes Opening tags in XML can have attributes. In a DTD, <!ATTLIST E... > declares attributes for element E, along with its datatype. 14

Example: Attributes Bars can have an attribute kind, a character string describing the bar. <!ELEMENT BAR (NAME BEER*)> <!ATTLIST BAR kind CDATA #IMPLIED> Character string type; no tags Attribute is optional opposite: #REQUIRED 15

Example: Attribute Use In a document that allows BAR tags, we might see: <BAR kind = sushi > <NAME>Homma s</name> <BEER><NAME>Sapporo</NAME>... </BAR> <PRICE>5.00</PRICE></BEER> 16

ID s and IDREF s Attributes can be pointers from one object to another. Compare to HTML s NAME = foo and HREF = #foo. Allows the structure of an XML document to be a general graph, rather than just a tree. 17

Creating ID s Give an element E an attribute A of type ID. When using tag <E > in an XML document, give its attribute A a unique value. Example: <E A = xyz > 18

Creating IDREF s To allow elements of type F to refer to another element with an ID attribute, give F an attribute of type IDREF. Or, let the attribute have type IDREFS, so the F -element can refer to any number of other elements. 19

Example: ID s and IDREF s A new BARS DTD includes both BAR and BEER subelements. BARS and BEERS have ID attributes name. BARS have SELLS subelements, consisting of a number (the price of one beer) and an IDREF thebeer leading to that beer. BEERS have attribute soldby, which is an IDREFS leading to all the bars that sell it. 20

The DTD <!DOCTYPE BARS [ <!ELEMENT BARS (BAR*, BEER*)> <!ELEMENT BAR (SELLS+)> <!ATTLIST BAR name ID #REQUIRED> <!ELEMENT SELLS (#PCDATA)> ]> <!ATTLIST SELLS thebeer IDREF #REQUIRED> <!ELEMENT BEER EMPTY> <!ATTLIST BEER name ID #REQUIRED> <!ATTLIST BEER soldby IDREFS #IMPLIED> Explained next Bar elements have name as an ID attribute and have one or more SELLS subelements. SELLS elements have a number (the price) and one reference to a beer. Beer elements have an ID attribute called name, and a soldby attribute that is a set of Bar names. 21

Example: A Document <BARS> <BAR name = JoesBar > <SELLS thebeer = Bud >2.50</SELLS> <SELLS thebeer = Miller >3.00</SELLS> </BAR> <BEER name = Bud soldby = JoesBar SuesBar /> </BARS> 22

Empty Elements We can do all the work of an element in its attributes. Like BEER in previous example. Another example: SELLS elements could have attribute price rather than a value that is a price. 23

Example: Empty Element In the DTD, declare: <!ELEMENT SELLS EMPTY> <!ATTLIST SELLS thebeer IDREF #REQUIRED> <!ATTLIST SELLS price CDATA #REQUIRED> Example use: <SELLS thebeer = Bud price = 2.50 /> Note exception to matching tags rule 24

XML Schema A more powerful way to describe the structure of XML documents. XML-Schema declarations are themselves XML documents. They describe elements and the things doing the describing are also elements. 25

Structure of an XML-Schema Document <? xml version =?> <xs:schema xmlns:xs = http://www.w3.org/2001/xmlschema >... </xs:schema> So uses of xs within the schema element refer to tags from this namespace. Defines xs to be the namespace described in the URL shown. Any string in place of xs is OK. 26

The xs:element Element Has attributes: 1. name = the tag-name of the element being defined. 2. type = the type of the element. Could be an XML-Schema type, e.g., xs:string. Or the name of a type defined in the document itself. 27

Example: xs:element <xs:element name = NAME type = xs:string /> Describes elements such as <NAME>Joe s Bar</NAME> 28

Complex Types To describe elements that consist of subelements, we use xs:complextype. Attribute name gives a name to the type. Typical subelement of a complex type is xs:sequence, which itself has a sequence of xs:element subelements. Use minoccurs and maxoccurs attributes to control the number of occurrences of an xs:element. 29

Example: a Type for Beers <xs:complextype name = beertype > <xs:sequence> <xs:element name = NAME type = xs:string minoccurs = 1 maxoccurs = 1 /> <xs:element name = PRICE type = xs:float minoccurs = 0 maxoccurs = 1 /> </xs:sequence> </xs:complextype> Like? in a DTD Exactly one occurrence 30

An Element of Type beertype <xxx> <NAME>Bud</NAME> <PRICE>2.50</PRICE> </xxx> We don t know the name of the element of this type. 31

Example: a Type for Bars <xs:complextype name = bartype > <xs:sequence> <xs:element name = NAME type = xs:string minoccurs = 1 maxoccurs = 1 /> <xs:element name = BEER type = beertype minoccurs = 0 maxoccurs = unbounded /> </xs:sequence> </xs:complextype> Like * in a DTD 32

xs:attribute xs:attribute elements can be used within a complex type to indicate attributes of elements of that type. attributes of xs:attribute: name and type as for xs.element. use = required or optional. 33

Example: xs:attribute <xs:complextype name = beertype > <xs:attribute name = name type = xs:string use = required /> <xs:attribute name = price type = xs:float use = optional /> </xs:complextype> 34

An Element of This New Type beertype <xxx name = Bud price = 2.50 /> We still don t know the element name. The element is empty, since there are no declared subelements. 35

Restricted Simple Types xs:simpletype can describe enumerations and range-restricted base types. name is an attribute xs:restriction is a subelement. 36

Restrictions Attribute base gives the simple type to be restricted, e.g., xs:integer. xs:{min, max}{inclusive, Exclusive} are four attributes that can give a lower or upper bound on a numerical range. xs:enumeration is a subelement with attribute value that allows enumerated types. 37

Example: license Attribute for BAR <xs:simpletype name = license > <xs:restriction base = xs:string > <xs:enumeration value = Full /> <xs:enumeration value = Beer only /> <xs:enumeration value = Sushi /> </xs:restriction> </xs:simpletype> 38

Example: Prices in Range [1,5) <xs:simpletype name = price > <xs:restriction base = xs:float mininclusive = 1.00 maxexclusive = 5.00 /> </xs:simpletype> 39

Keys in XML Schema An xs:element can have an xs:key subelement. Meaning: within this element, all subelements reached by a certain selector path will have unique values for a certain combination of fields. Example: within one BAR element, the name attribute of a BEER element is unique. 40

Example: Key <xs:element name = BAR >... <xs:key name = barkey > <xs:selector xpath = BEER /> <xs:field xpath = @name /> </xs:key>... </xs:element> XPath is a query language for XML. All we need to know here is that a path is a sequence of tags separated by /. And @ indicates an attribute rather than a tag. 41

Foreign Keys An xs:keyref subelement within an xs:element says that within this element, certain values (defined by selector and field(s), as for keys) must appear as values of a certain key. 42

Example: Foreign Key Suppose that we have declared that subelement NAME of BAR is a key for BARS. The name of the key is barkey. We wish to declare DRINKER elements that have FREQ subelements. An attribute bar of FREQ is a foreign key, referring to the NAME of a BAR. 43

Example: Foreign Key in XML Schema <xs:element name = DRINKERS... <xs:keyref name = barref refers = barkey <xs:selector xpath = DRINKER/FREQ /> <xs:field xpath = @bar /> </xs:keyref> </xs:element> 44