Last week we saw how to use the DOM parser to read an XML document. The DOM parser can also be used to create and modify nodes.

Similar documents
Markup Languages. Lecture 4. XML Schema

XML. Document Type Definitions XML Schema. Database Systems and Concepts, CSCI 3030U, UOIT, Course Instructor: Jarek Szlichta

Semantic Web. XML and XML Schema. Morteza Amini. Sharif University of Technology Fall 94-95

Modelling XML Applications (part 2)

XML extensible Markup Language

Software Engineering Methods, XML extensible Markup Language. Tutorial Outline. An Example File: Note.xml XML 1

PESC Compliant JSON Version /19/2018. A publication of the Technical Advisory Board Postsecondary Electronic Standards Council

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

So far, we've discussed the use of XML in creating web services. How does this work? What other things can we do with it?

Jeff Offutt. SWE 642 Software Engineering for the World Wide Web

XEP-0009: Jabber-RPC

Modelling XML Applications

Java EE 7: Back-end Server Application Development 4-2

XML. extensible Markup Language. Overview. Overview. Overview XML Components Document Type Definition (DTD) Attributes and Tags An XML schema

QosPolicyHolder:1 Erratum

Marker s feedback version

XML Schema Element and Attribute Reference

PESC Compliant JSON Version /04/2019

XML Format Plug-in User s Guide. Version 10g Release 3 (10.3)

EMERGING TECHNOLOGIES. XML Documents and Schemas for XML documents

Introducing our First Schema

markup language carry data define your own tags self-descriptive W3C Recommendation

Tutorial 2: Validating Documents with DTDs

MCS-274 Final Exam Serial #:

XML. Part II DTD (cont.) and XML Schema

Using and defining new simple types. Basic structuring of definitions. Copyright , Sosnoski Software Solutions, Inc. All rights reserved.

XML Schema. Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 28

UPDATES TO THE LRIT SYSTEM. Report of the Drafting Group

[MS-MSL]: Mapping Specification Language File Format. Intellectual Property Rights Notice for Open Specifications Documentation

Restricting complextypes that have mixed content

[MS-OXWSSYNC]: Mailbox Contents Synchronization Web Service Protocol Specification

XEP-0298: Delivering Conference Information to Jingle Participants (Coin)

2006 Martin v. Löwis. Data-centric XML. XML Schema (Part 1)

Session [2] Information Modeling with XSD and DTD

[MS-OXWSMSHR]: Folder Sharing Web Service Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

XML DTDs and Namespaces. CS174 Chris Pollett Oct 3, 2007.

HTML vs. XML In the case of HTML, browsers have been taught how to ignore invalid HTML such as the <mymadeuptag> element and generally do their best

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

TED schemas. Governance and latest updates

XML, DTD, and XML Schema. Introduction to Databases CompSci 316 Fall 2014

CS561 Spring Mixed Content

Big Data 9. Data Models

Semistructured Content

ADT 2005 Lecture 7 Chapter 10: XML

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

Chapter 11 XML Data Modeling. Recent Development for Data Models 2016 Stefan Deßloch

Schema schema-for-json.xsd

Introduction to Semistructured Data and XML. Overview. How the Web is Today. Based on slides by Dan Suciu University of Washington

Big Data for Engineers Spring Data Models

Semistructured Content

Web Computing. Revision Notes

Expressing Internationalization and Localization information in XML

PART. Oracle and the XML Standards

Document Metadata: document technical metadata for digital preservation

The Essence of XML. Jérôme Siméon, Bell Labs, Lucent Philip Wadler, Avaya Labs

Big Data Fall Data Models

IBM. XML and Related Technologies Dumps Braindumps Real Questions Practice Test dumps free

PRELIMINARY. No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

XEP-0171: Language Translation

Automatic Configurator for Application Code

11. Documents and Document Models

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

ABSTRACT 1. INTRODUCTION

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

MANAGING INFORMATION (CSCU9T4) LECTURE 2: XML STRUCTURE

TIBCO BusinessWorks COBOL Copybook Plug-in User s Guide. Software Release 2.5 October 2008

Session 23 XML. XML Reading and Reference. Reading. Reference: Session 23 XML. Robert Kelly, 2018

Introduction & Motivation. Course Outline. Arrangements. Presentation vs Structure. Markup and Markup Language. Main Topic: Two XML Query Models

QosPolicyHolder 1.0. For UPnP Version Date: March 10th, 2005

Transforming XBRL into an OWL Ontology

WSDL versioning. Facts Basic scenario. WSDL -Web Services Description Language SAWSDL -Semantic Annotations for WSDL and XML Schema

Document erratum applies to QosDevice:1. List other Erratum s or Documents that this change may apply to or have associated changes with

XML and Web Services

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

Syntax XML Schema XML Techniques for E-Commerce, Budapest 2004

XML (Extensible Markup Language)

XML. COSC Dr. Ramon Lawrence. An attribute is a name-value pair declared inside an element. Comments. Page 3. COSC Dr.

Comp 336/436 - Markup Languages. Fall Semester Week 4. Dr Nick Hayward

No Trade Secrets. Microsoft does not claim any trade secret rights in this documentation.

Structured documents

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

DTD MIGRATION TO W3C SCHEMA

XML Schema for WSML. Table of Contents

G16-02SE-A02.1-NUE112_SchedaContatto-Rev5 <?xml version="1.0" encoding="utf-8"?> <xs:schema xmlns:xs="

[MS-OXWSGTZ]: Get Server Time Zone Web Service Protocol. Intellectual Property Rights Notice for Open Specifications Documentation

All About <xml> CS193D, 2/22/06

X3D Unit Specification Updates Myeong Won Lee The University of Suwon

XML Schema types and equivalence classes

Framing how values are extracted from the data stream. Includes properties for alignment, length, and delimiters.

COMP9321 Web Application Engineering. Extensible Markup Language (XML)

Trustmark Framework Technical Specification

Altova XMLSpy 2007 Tutorial

Mapping IDABC Authentication Assurance Levels to SAML V2.0

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

Enforcing Id In Xml Schema Enumeration >>>CLICK HERE<<<

[MS-SSDL]: Store Schema Definition Language File Format. Intellectual Property Rights Notice for Open Specifications Documentation

XML Origin and Usages

[MS-OXWSXPROP]: Extended Properties Structure. Intellectual Property Rights Notice for Open Specifications Documentation

SDMX self-learning package No. 6 Student book. XML Based Technologies Used in SDMX

Altova XMLSpy 2013 Tutorial

Transcription:

Distributed Software Development XML Schema Chris Brooks Department of Computer Science University of San Francisco 7-2: Modifying XML programmatically Last week we saw how to use the DOM parser to read an XML document. The DOM parser can also be used to create and modify nodes. 7-3: Creating new nodes The top-level Node in an XML document is of class Document It contains a set of factory methods that allow you to create new nodes. doc = minidom.parse( cdcat.xml ) doc.createelement( songs ) doc.createtextnode( Tomorrow Never Knows ) doc.createattribute( encoding ) After creating a node, it can be added to the tree. cisco p. 1/?? cisco p. 2/?? 7-4: Adding nodes We then insert nodes by attaching them to existing nodes. node.appendchild(newnode) node.insertbefore(newnode, childafter) node.replacechild(newnode, oldnode) We can also remove nodes: node.removechild(nodename) 7-5: Example def changerating(artist, newrating) : cds = doc.getelementsbytagname( cd ) for item in cds : a = item.getelementsbytagname( artist ) if a[0].firstchild.data.strip() == artist.strip() : r = item.getelementsbytagname( rating ) r[0].replacechild(doc.createtextnode(newrating), r[0].firstchild) return doc 7-6: Example def addlabel(artist, label) : cds = doc.getelementsbytagname( cd ) print cds for item in cds : print item a = item.getelementsbytagname( artist ) if a[0].firstchild.data.strip() == artist.strip() : n = doc.createelement( Label ) n.appendchild(doc.createtextnode(label)) item.appendchild(n) print cds[1].toxml() return doc cisco p. 4/?? cisco p. 5/??

7-7: Defining XML documents Recall that, unlike HTML, an XML author can declare any tags he or she wants. If you re just making your own simple documents, an ad hoc approach can work fine. If you re building more complex applications, need to incorporate legacy data, or need to exchange data with others, this may not be suitable. XML Schema are a way to formally define legal XML documents. 7-8: Data Interchange A challenge in exchanging data between heterogenous systems is ensuring that all participants agree on the meaning and representation of the data. Is author a sub-element of book, or the other way around? Do all books have to have an ISBN tag, or is it optional? What is the format of a valid ISBN number? Must price be a float? Is there an order that elements must occur in? XML allows users of data to validate this data against a schema. 7-9: DTDs vs Schema There are (at least) two different mechanisms for specifying the legal structure of an XML document. DTDs XML Schema DTDs are an older technology Less flexible, but still found in many documents. XML Schema are a newer, W3C-backed standard. cisco p. 7/?? cisco p. 8/?? 7-10: DTDs A Document Type Definition is information about the legal structure of an XML document. A DTD allows you to specify the set of allowable elements (the vocabulary), how they fit together (the grammar), and the legal values that can be assigned to them (their semantics). 7-11: DTD example <!-- BTW, here s how to add a comment. This is our book DTD --! <!ELEMENT book (author+, subtitle?, title, price+, publisher+, isbn, (volumes description)*) <!ELEMENT author (#PCDATA) <!ELEMENT title (#PCDATA) <!ELEMENT volumes volume+ <!ELEMENT volume (#PCDATA) <!ELEMENT publisher (#PCDATA) <!ELEMENT isbn (#PCDATA) <!ATTLIST book genre (fantasy sci-fi mystery horror) fantasy id ID #REQUIRED 7-12: Weaknesses of DTDs DTDs are still used, often for backward compatibility. Weaknesses: Not XML - require a different parser. Can t constrain ranges Overly restrictive about order. cisco p. 10/?? cisco p. 11/??

7-13: XML Schema XML Schema are one of several proposed techniques for describing how elements can be arranged. DTDs are the other common way to do this. Schemata are more flexible and expressive than DTDs Backed by W3C Essentially an XML document that describes XML documents. Allow you to specify order, data types, number of occurrences, etc. 7-14: An example (see external example) 7-15: Using a schema We can then use the schema to validate an XML document. This lets us programmatically ensure that the document is well-formed. Helps with data integration, testing output, verifying received data. Schemata also serve as a form of documentation Can also be used to provide application-level and parsing guidance. cisco p. 13/?? cisco p. 14/?? 7-16: Schema datatypes Schema let us specify what data types an element can have: xs:string - any text xs:token - tokens separated by whitespace decimal - float xs:integer - integer xs:id - - provides a unique identifier xs:boolean - true or false xs:datetime - 2004-11-03T11:03:00-10:00 7-17: Complex types Many interesting XML elements are not just simple data types, but are are compositions of simple types. For example, let s say we want a date element that looks like this: <date <month 12 </month <day 13 </day <year 1972 </year </date 7-18: Complex types A Schema for this would look like: <xs:element name= date <xs:complextype <xs:all <xs:element ref= year / <xs:element ref= month / <xs:element ref= day / </xs:all </xs:complextype </xs:element <xs:element name= year type= xs:integer / <xs:element name= month type= xs:integer / <xs:element name= day type= xs:integer cisco p. 16/?? cisco p. 17/??

7-19: Value Restrictions We might also want to specify that months must be between 1 and 12. We do this by making a new type. <xs:simpletype name="monthnum" <xs:restriction base="xs:integer" <xs:mininclusive value="1"/ <xs:maxinclusive value="12"/ </xs:restriction </xs:simpletype <xs:element name="month" type="monthnum"/ 7-20: Value Restrictions We can also specify patterns that an element must follow, using a regular expression. For example, let s say we want to specify that a price is one or more numbers, followed by a decimal point, followed by two numbers. <xs:element name= price type= priceval <xs:simpletype name= priceval <xs:restriction base= xs:token <xs:pattern value= [0-9]+_[0-9]2 / </xs:restriction </xs:simpletype 7-21: Value Restrictions We can also define particular values that an element can take on with an enumeration. <xs:simpletype name="gendertype" <xs:restriction base="xs:token" <xs:enumeration value="female"/ <xs:enumeration value="male"/ </xs:restriction </xs:simpletype cisco p. 19/?? cisco p. 20/?? 7-22: Groupings XML Schema provide a number of tools for grouping elements. xs:choice <xs:choice minoccurs="0" <xs:element ref="junior"/ <xs:element ref="senior"/ </xs:choice xs:all maxoccurs=n xs:enumeration xs:sequence 7-23: Referencing Schema Once your schema is defined, it can be referenced from within an instance document. <book xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation = "http://www.cs.usfca.edu/xml-schema/tolkien.xsd" The first line provides a reference to the definition of xsi:schemalocation. The second line points to the actual URI of the schema. 7-24: Namespaces A big advantage of Schemata is the ability to incorporate multiple schemata within a single document. Each schema has its own namespace, indicated by a prefix on the element. <book xmlns:usf1 = "http://www.cs.usfca.edu/xml-schema" xmlns:usf2 = "http://www.cs.usfca.edu/newschema/" <usf1:title Here s the book title </usf1:title <usf2:title Here s another type of title </usf2:title </book Note that, in practice, there s no promise that the URIs will resolve to actual schema. cisco p. 22/?? cisco p. 23/??

7-25: Summary Schemata provide a mechanism to formally define the legal structure of an XML document. Allow you to specify data types, required elements, and values. This allows you to validate an XML document. Like many things on the WWW, standards are evolving and incompletely implemented. cisco p. 25/??