Exercises: XSD, XPath Basi di da4 2



Similar documents
Exercises: DTD Basi di da/ 2

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

Allegato XML flusso richieste di produzione

XML Schema Definition Language (XSDL)

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

XML and Data Management

<?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:niso="

Et tu, XML? Philip Wadler, Avaya Labs

XML Based Customizable Screen. Rev 1.1

How To Write A Technical Interoperability Standard For Spain

XML. Dott. Nicole NOVIELLI XML: extensible Markup Language

The A2A Data Model and its application in WieWasWie. Michel

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

Device Feature Key Synchronization

INTEGRATING WEB SERVICES INTO A WEB-BASED COLLEGE ADMISSION PORTAL SYSTEM

Geography Markup Language (GML) simple features profile

<xs:complextype name="trescdokumentu_typ">

Java and XML parsing. EH2745 Lecture #8 Spring

XML-BASED AUTOMATIC TEST DATA GENERATION

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

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

XML for RPG Programmers: An Introduction

Certificates, Certification Authorities and Public-Key Infrastructures

<Namespaces> Core XML Technologies. Why Namespaces? Namespaces - based on unique prefixes. Namespaces. </Person>

How To Write A Contract Versioning In Wsdl 2.2.2

Database Technologies

Visualization of GML data using XSLT.

Comparison of IEC CIM and NRECA MultiSpeak

Chapter 15 Working with Web Services

ipratico POS Quick Start Guide v. 1.0

DTD Tutorial. About the tutorial. Tutorial

XML: extensible Markup Language. Anabel Fraga

Odoo 8.0. Le nuove API.

Selling on Amazon Guide to XML

Main Points. File layout Directory layout

Please see the attached file: "SendExample.asp" for an example of how you can send files using classic ASP.

XML for Analysis Specification. Version 1.1 Microsoft Corporation Hyperion Solutions Corporation Updated: 11/20/2002

Chapter 2: Designing XML DTDs

[MS-MDE]: Mobile Device Enrollment Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

Connecting to WebSphere ESB and WebSphere Process Server

XML. Document Type Definitions XML Schema

L ordine perfet to. In perfect order. Attuatore elettrico a stelo per apertura e chiusura di finestre a sporgere, a lamelle, pale frangisole e cupole

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

COPIA TRATTA DA GURITEL GAZZETTA UFFICIALE ON-LINE

CHAPTER 9: DATAPORT AND XMLPORT CHANGES

Temando Api. Release Developer Documentation. Temando IT Department

Parallels Operations Automation 5.4

I N T R E C C I O R O M B I

Istituto Tecnico Commerciale e per Geometri S. Bandini Siena

Source code security testing

Versione: 2.1. Interoperabilità del Sistema di Accettazione di SPT

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

The molecules of life. The molecules that make up living things are really big They are called macromolecules

DIRECTORS AND OFFICERS PROPOSTA DI POLIZZA

Translating between XML and Relational Databases using XML Schema and Automed

Tecnologie per XML. Sara Comai Politecnico di Milano. Tecnologie legate a XML

Tecnologie e Protocolli per Internet 1 Introduzione al NAT Network Address Translation

XML - A Practical Application and Design

Lesson 201: Use of il quale

Questionario Medico Medical Questionnaire

ATWD XML Web Service Handbook

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

Semistructured data and XML. Institutt for Informatikk INF Ahmet Soylu

EHR-IIS Interoperability Enhancement Project. Transport Layer Protocol Recommendation Formal Specification. Version 1.

Lecture 10. Subnetting & Supernetting

ITIL v3 - Overview. Claudio Tancini Marzo 2015 INTERNAL USE ONLY

Banners Broker è una. Compagnia di pubblicità online

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

From Open Data & Linked Data to Ontology. example:

SISTEMA ANTE EVO 2 DOOR SYSTEM EVO 2

Lesson 4 Web Service Interface Definition (Part I)

Accounting and Settlement: Technical Information

Catalogo generale / General catalogue

Centro Linguistico di Ateneo

Exercise 2 Dialogue(Dialogo)

Modello dati regionale d interscambio del Piano Strutturale Comunale (PSC) Allegato A Formato GML-XML

Transcription:

Exercises: XSD, XPath Basi di da4 2 Disheng Qiu disheng.qiu@gmail.com Luca Rossi luca.rossi.917@gmail.com

Hints: Use a validator XSD Eclipse has a plugin for XML/XSD/DTD valida4on W3C Validator: hmp://www.w3.org/2001/03/webdata/xsv Another Validator: hmp://www.xmlforasp.net/schemavalidator.aspx XPath Guess what? There s a plugin for Eclipse Extensions for Firefox and Chrome

Exercises: 1x From XSD to instance 2x From instance to XSD 1x From specs to XSD

Exercise 1: Cara%ere From XSD to instance

Ex.1 - From XSD to instance: Cara%ere <?xml version="1.0"?> <xsd:schema xmlns:xsd= hmp://www.w3.org/2001/xmlschema"> <xsd:simpletype name="cifra"> <xsd:restric4on base="xsd:string"> <xsd:pamern value="[0-9]"/> </xsd:restric4on> </xsd:simpletype> <xsd:simpletype name="caramere"> <xsd:restric4on base="xsd:string"> <xsd:pamern value="[a- Z]"/> </xsd:restric4on> </xsd:simpletype> <xsd:element name="car" type="caramere"/> <xsd:element name="num" type="cifra"/> <xsd:element name="esercizio" type="tesercizio"/> <xsd:complextype name="tesercizio"> <xsd:sequence> <xsd:element ref="car" minoccurs="6" maxoccurs="6"/> <xsd:element ref="num" minoccurs="2" maxoccurs="2"/> <xsd:element ref="car"/> <xsd:element ref="num" minoccurs="2" maxoccurs="2"/> <xsd:element ref="car"/> <xsd:element ref="num" minoccurs="3" maxoccurs="3"/> <xsd:element ref="car"/> </xsd:sequence> </xsd:complextype> </xsd:schema>

Ex.1 - From XSD to instance: Cara%ere <xsd:simpletype name="cifra"> <xsd:restric4on base="xsd:string"> <xsd:pamern value="[0-9]"/> </xsd:restric4on> </xsd:simpletype> <xsd:simpletype name="caramere"> <xsd:restric4on base="xsd:string"> <xsd:pamern value="[a- Z]"/> </xsd:restric4on> </xsd:simpletype> <xsd:element name="car" type="caramere"/> <xsd:element name="num" type="cifra"/> <xsd:element name="esercizio" type="tesercizio"/> <xsd:complextype name="tesercizio"> <xsd:sequence> Many styles of XSD: Anonymous vs Nominal types Local vs Global elements <xsd:element ref="car" minoccurs="6" maxoccurs="6"/> <xsd:element ref="num" minoccurs="2" maxoccurs="2"/> <xsd:element ref="car"/> <xsd:element ref="num" minoccurs="2" maxoccurs="2"/> <xsd:element ref="car"/> <xsd:element ref="num" minoccurs="3" maxoccurs="3"/> <xsd:element ref="car"/> </xsd:sequence> </xsd:complextype>

Ex.1 - Solu4on <esercizio> <car>x</car><car>x</car><car>x</car> <car>y</car><car>y</car><car>y</car> <num>1</num><num>1</num> <car>z</car> <num>2</num><num>2</num> <car>h</car> <num>3</num><num>3</num><num>3</num> <car>k</car> </esercizio>

Exercise 2: Binario From specs to XSD

Ex.2 - From specs to XSD: Binario Define a XSD that validates XML documents describing binary strings. The root element <binario> contains an arbitrary sequence of elements <uno> and <zero>, in any order.

Ex.2 - Solu4on <xsd:element name="binario"> <xsd:complextype> <xsd:choice minoccurs="0" maxoccurs="unbounded"> <xsd:element name="zero" type="xsd:unsignedbyte" fixed="0"/> <xsd:element name="uno" type="xsd:unsignedbyte" fixed="1"/> </xsd:choice> </xsd:complextype> </xsd:element> - - - <binario> <uno>1</uno> <zero>0</zero> <zero>0</zero> <uno>1</uno> </binario>

Exercise 3: Le%era From instance to XSD

Ex.3 - From instance to XSD: LeMera <lemera> Gen4le <cliente> tal dei tali </cliente>, la informiamo che i seguen4 ar4coli da lei ordina4 non sono più disponibili a magazzino: <ordine num="1234"> <ar4colo> <codice>1</codice> <descr>ar4colo 1</descr> </ar4colo> <ar4colo> <codice>5</codice> <descr>ar4colo 5</descr> </ar4colo> </ordine> Cordiali salu4, <responsabile><4t>dr.</4t>mario Rossi</responsabile> </lemera>

Ex.3 Solu4on (Global elements, nominal types)

Exercise 4: Catena Montuosa From instance to XSD

Ex.4 - From instance to XSD: Catena Montuosa <catenamontuosa> <monte> <nome> Monte Bianco </nome> <regione> Valle d Aosta </regione> <altezza unitamisura="metri">4810</altezza> </monte> <monte> <nome>gransasso</nome> </monte> </catenamontuosa>

Ex.4 Solu4on 1 (Local elements, anonymous types)

Ex.4 Solu4on 2 (Global elements, anonymous types)

Exercise 5: XPath

Ex.5 - DTD <!ELEMENT recipes (recipe*)> <!ELEMENT recipe (4tle, ingredient+, prepara4on, comment?, nutri4on)> <!ELEMENT 4tle (#PCDATA)> <!ELEMENT ingredient (ingredient*,prepara4on?)> <!ATTLIST ingredient name CDATA #REQUIRED amount CDATA #IMPLIED unit CDATA #IMPLIED> <!ELEMENT prepara4on (step+)> <!ELEMENT step (#PCDATA)> <!ELEMENT nutri4on EMPTY> <!ELEMENT comment (#PCDATA)> <!ATTLIST nutri4on calories CDATA #REQUIRED fat CDATA #REQUIRED carbohydrates CDATA #REQUIRED protein CDATA #REQUIRED alcohol CDATA #IMPLIED>

Ex.5 - Instance <recipes> <recipe> <4tle>Beef Parmesan</4tle> <ingredient name="beef" amount="1.5" unit="pound"/> <ingredient name="onion" amount="1"/> <ingredient name="green rings" amount="1"/> <prepara4on> <step>boil pasta</step> </prepara4on> <comment> </comment> <nutri4on calories="1167" fat="23"carbohydrates="45" protein="32"/> </recipe>. </recipes>

Ex.5 XPath Queries 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. 5. "The first two steps in preparing Zuppa Inglese. 6. " The 4tles of all recipes that requires five steps. 7. "The recipes that have an ingredient in common with Zuppa Inglese. 8. "The 4tles of recipes have some compound ingredients."

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. //recipe[ingredient/@name="olive oil"]/4tle

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. //recipe[ingredient/@name="olive oil"]/4tle NO (AMenzione agli ingredien4 nidifica4) //recipe[.//ingredient/@name="olive oil"]/4tle (Vogliamo omenetere 4toli come ELEMENTI o come testo?) SI //recipe[.//ingredient/@name="olive oil"]/4tle/text() SI

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. //4tle/text() (è possibile specificare il documento tramite fn:doc("recipes.xml"))

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. //recipe[//@calories < 500]/4tle

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. //recipe[//@calories < 500]/4tle NO (Bisogna specificare l amributo di quale elemento - // nelle parantesi torna da root) //recipe[nutri4on/@calories < 500]/4tle SI

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. number(//recipe[4tle="zuppa Inglese"]//ingredient[@name="sugar"]/@amount) (ritorna un numerico dell ammontare dello zucchero NON ESEGUE LA SOMMA)

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. 5. "The first two steps in preparing Zuppa Inglese. //recipe[4tle="zuppa Inglese"]/prepara4on/step[posi4on()=1 or posi4on()=2]

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. 5. "The first two steps in preparing Zuppa Inglese. 6. " The 4tles of all recipes that requires five steps.

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. 5. "The first two steps in preparing Zuppa Inglese. 6. " The 4tles of all recipes that requires five steps. //recipe[.//step[5]]/4tle //recipe[prepara4on/step[5]]/4tle

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. 5. "The first two steps in preparing Zuppa Inglese. 6. " The 4tles of all recipes that requires five steps. 7. "The recipes that have an ingredient in common with Zuppa Inglese. //recipe[.//ingredient/@name=//recipe[4tle="zuppa Inglese"]//ingredient/@name]

Ex.5 - Solu4on 1. "The 4tles of all recipes that use olive oil. 2. "The 4tles of all recipes, returned as strings. 3. "The 4tles of all recipes with less than 500 calories. 4. "The amount of sugar needed for Zuppa Inglese. 5. "The first two steps in preparing Zuppa Inglese. 6. " The 4tles of all recipes that requires five steps. 7. "The recipes that have an ingredient in common with Zuppa Inglese. 8. "The 4tles of recipes have some compound ingredients. //recipe[ingredient/ingredient]/4tle