XML Schema - Lecture Slides | Distributed Software Development | CS 682, Study notes of Software Engineering

Material Type: Notes; Class: Distributed Software Develop; Subject: Computer Science; University: University of San Francisco (CA); Term: Spring 2006;

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-mfx
koofers-user-mfx 🇺🇸

9 documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Distributed Software Development
XML Schema
Chris Brooks
Department of Computer Science
University of San Francisco
Department of Computer Science University of San Francisco p. 1/??
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download XML Schema - Lecture Slides | Distributed Software Development | CS 682 and more Study notes Software Engineering in PDF only on Docsity!

Distributed Software Development

XML Schema

Chris Brooks

Department of Computer ScienceUniversity of San Francisco

Department of Computer Science — University of San Francisco – p. 1/

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

Department of Computer Science — University of San Francisco – p. 2/

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)

Department of Computer Science — University of San Francisco – p. 4/

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

Department of Computer Science — University of San Francisco – p. 5/

Defining XML documents • Recall that, unlike HTML, an XML author can declare any tagshe or she wants. • If you’re just making your own simple documents, an ad hocapproach can work fine. • If you’re building more complex applications, need toincorporate legacy data, or need to exchange data with others,this may not be suitable. • XML Schema are a way to formally define legal XMLdocuments.

Department of Computer Science — University of San Francisco – p. 7/

Data Interchange • A challenge in exchanging data between heterogenoussystems is ensuring that all participants agree on the meaningand 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

.

Department of Computer Science — University of San Francisco – p. 8/

DTDs • A Document Type Definition is information about the legalstructure of an XML document. • A DTD allows you to specify the set of allowable elements (thevocabulary), how they fit together (the grammar), and the legalvalues that can be assigned to them (their semantics).

Department of Computer Science — University of San Francisco – p. 10/

7-11:

DTD example