

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Distributed Software Develop; Subject: Computer Science; University: University of San Francisco (CA); Term: Spring 2006;
Typology: Study notes
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















Distributed Software Development
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