0% found this document useful (0 votes)
48 views

Correction: DTD Examples (I)

This document provides examples and explanations of DTDs and XML documents. It discusses: 1) The difference between DTDs and XML documents, with DTDs specifying structural rules and XML documents adhering to those rules. 2) An example DTD and XML document for an email application that defines elements like <from>, <to>, <subject>, and <body>. 3) Another example of a DTD and hypothetical XML documents for a library application that would store book information and related data. 4) Key differences between elements and attributes in XML, with elements representing structured data and attributes providing atomic descriptive data.

Uploaded by

swapnil kale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Correction: DTD Examples (I)

This document provides examples and explanations of DTDs and XML documents. It discusses: 1) The difference between DTDs and XML documents, with DTDs specifying structural rules and XML documents adhering to those rules. 2) An example DTD and XML document for an email application that defines elements like <from>, <to>, <subject>, and <body>. 3) Another example of a DTD and hypothetical XML documents for a library application that would store book information and related data. 4) Key differences between elements and attributes in XML, with elements representing structured data and attributes providing atomic descriptive data.

Uploaded by

swapnil kale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Correction: DTD Examples (I)

More on XML
„ <!ELEMENT name (#PCDATA)>
„ <name>John</name>
(The slides that were skipped in the last lecture)

1 2

DTD vs. XML Document Example: a Simple XML Email Application


email.dtd email.xml
„ DTD specifies the structural syntactic rules <!ELEMENT email (from, to, date, <?xml version="1.0" encoding="ISO-
subject, body)> 8859-1" ?>
„ Specify the allowed tags and attributes, the order <!ELEMENT from (#PCDATA)> <!DOCTYPE email SYSTEM
<!ELEMENT to (#PCDATA)> “email.dtd” >
of appearance, and arrangements <!ELEMENT date (#PCDATA)> <email priority=“high”>
<!ELEMENT subject (#PCDATA)> <from>Jani</from>
„ XML documents are created based on the <!ELEMENT body (#PCDATA)> <to>Tony</to>
<date>September 20, 2007</date>
XML low-level and DTD syntax rules <!ATTLIST email
priority (high|normal|low) normal> <subject>Reminder</subject>
<body>Don't forget to email me this
„ An XML document is said to be well-formed if weekend!</body>
</email>
it adheres to only the low-level syntax rules
„ An XML document can be created without any DTD
„ An XML document is said to be valid if it
adheres to both sets of syntax rules
3 4

Example: an XML library application library.dtd


„ Write an XML application for storing information about <!ELEMENT library (book+)>
<!ELEMENT book (title, author+, publisher, description, related*)>
books in a library <!ELEMENT title (#PCDATA)>
„ Include the following information: <!ELEMENT author ((firstname, lastname)|(lastname, firstname))>
<!ELEMENT publisher (#PCDATA)>
„ title <!ELEMENT description (#PCDATA)>
„ author <!ELEMENT related EMPTY>
„ publisher
<!ELEMENT firstname (#PCDATA)>
„ description
<!ELEMENT lastname (#PCDATA)>
„ type (one of fiction, non-fiction, cookbook, technical)
„ ISBN <!ATTLIST book
„ book id for internal purposes bookid ID #REQUIRED
type (fiction|non-fiction|cookbooks|technical) #REQUIRED
„ set of related books isbn CDATA #REQUIRED>
„ flag the best of the related books
<!ATTLIST related bookref IDREF #REQUIRED>
<!ATTLIST related class CDATA #IMPLIED>
5 6

1
Element vs. Attribute Elements vs. Attributes
„ Element Elements Attributes
„ Data can be considered independent objects Can have child Elements Can contain only strings, or
„ Data is related via a parent/child relationship nested within them lists of strings
„ Item needs to occur multiple times Structured and simple data Used for atomic data items
„ Ordering required May have to appear in order Can only appear once in an
„ Attribute as specified, but may be element
„ Information that describes the element more than once
„ Such as status or id Natural, core content, which Secondary data, often
„ Valuesare limited would generally appear in metadata
„ A property of element every printout/display
(Sub-)Elements represent Properties of an Element
http://xml.coverpages.org/draft-stuhec-elemvsattrib-03-20020316.pdf parts of an Element
7 8

XML Reference Architecture

Application
XML and DOM
XML
Processor
Parsing XML

XML
File

9 10

DOM Parsing XML with DOM


„ DOM (Document Object Model) var xmlDoc =
document.implementation.createDocument(
namespace, name, doctype);
„ Generates tree-like structure of XML xmlDoc.load(“mydoc.xml”);
document in memory „ Treat XML files as data sources
„ Programs traverse the document tree „ Supports both synchronous and asynchronous loading
„ Default is asynchronous
„ Need to provide an event handler
„ xmlDoc.addEventListener(“load”, handlerName)
„ To use synchronous loading, set the following before loading
„ xmlDoc.async = false;
„ Getting a reference to the document element
„ xmlDoc.documentElement
„ Returns the root element
11 12

2
The Four Steps
1. Develop a data model
„ What information are you going to store and how will you represent it?
2. Develop a collection of legal transactions on that model
„ E.g., inserts and updates
3. Design the page flow
Building Internet Applications „ How will the user interact with the system?
„ What steps will lead up to one of those legal transactions?
„ An Internet service lives or dies by Steps 1 through 3
„ What can the service do for the user?
„ Is the page flow comprehensible and usable?
http://philip.greenspun.com/seia/basics „ The answers to these questions are determined at Steps 1 through 3
4. Implement the individual pages
„ You'll be writing scripts that query information from the data model, wrap that
information in XHTML, and return the combined result to the user
„ This step is intellectually uninteresting and also uninteresting from an
engineering point of view
„ However, this is where you have a huge range of technology choices

13 14

You might also like