Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML and DTD Please you speaker notes for additional information!

Similar presentations


Presentation on theme: "XML and DTD Please you speaker notes for additional information!"— Presentation transcript:

1 XML and DTD Please you speaker notes for additional information!

2 <!DOCTYPE customer [ ]> 11111 Susan Ash 12 Elm St Braintree MA 02184 This holds just one customer - customer is the root. The elements are the declarations. I used the xml document shown here in a html program on the next slide to produce the output that you see. Note that the data you see comes from the xml, the rest of the information comes from the html.

3 Customers Fall River Store 112 Main Street Fall River, MA Customer Id: Name: Address: City: State: Zip: This prints the header information at the top of the screen. This establishes Customer_Id as customer.xml. This code establishes which data field is to be shown from the xml. This shows the identifying literals.

4 <!DOCTYPE customers [ ]> 11111 Susan Ash 12 Elm St Braintree MA 02184 22222 Stephen Daniels 45 East St Brooklyn NY 11211 I now want to add a second customer to my data. To do this I make the root the name of the customer group or collection (customers) and each individual customer becomes a record (customer).

5 Customers Fall River Store 112 Main Street Fall River, MA Customer Id: Name: Address: City: State: Zip:

6 First <button onClick="Customer_Data.recordset.movePrevious(); if (Customer_Data.recordset.BOF) Customer_Data.recordset.moveFirst()"> Previous <button onClick="Customer_Data.recordset.moveNext(); if (Customer_Data.recordset.EOF) Customer_Data.recordset.moveLast()"> Next Last

7 <!DOCTYPE customers [ ]> 11111 Susan Ash 12 Elm St Braintree MA 02184 22222 Stephen Daniels 45 East St Brooklyn NY 11211 When using the DTD you specify: <!DOCTYPE root [ declarations ]> The first element says that customers (the root element), can contain one or more occurrences of customer. The customer element contains 6 child elements that are listed. Each child element is listed individually and is given the #PCDATA which indicates character/string data.

8 <!DOCTYPE customers [ ]> Susan Ash 12 Elm St Braintree MA 02184 Stephen Daniels 45 East St Brooklyn NY 11211 In this example, custid is not a child element, it is an attribute of customer. ID means calls for uniqueness and #REQUIRED means an entry is required. Quote from w3schools: “Should you avoid using attributes? Here are some of the problems using attributes: * attributes cannot contain multiple values (child elements can) * attributes are not easily expandable (for future changes) * attributes cannot describe structures (child elements can) * attributes are more difficult to manipulate by program code * attribute values are not easy to test against a DTD If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data. To validate, I used: http://validator.w3.org/

9 <!DOCTYPE donors [ <!ELEMENT donor(name, address, yrfirst?, contact?) <!ELEMENT name (#PCDATA) ]> John Doe <![CDATA[ 123 Elm St Braintree, MA 02184 ]]> 1995 Ann Smith

10

11 <!DOCTYPE donors [ <!ELEMENT donor(name, address, yrfirst?, contact?) <!ELEMENT name (#PCDATA) ]> John Doe <![CDATA[ 123 Elm St Braintree, MA 02184 ]]> 1995 Ann Smith Need the > at the end.

12 <!DOCTYPE donors [ ]> John Doe <![CDATA[ 123 Elm St Braintree, MA 02184 ]]> 1995 Ann Smith

13

14 <!DOCTYPE donors [ ]> John Doe <![CDATA[ 123 Elm St Braintree, MA 02184 ]]> 1995 Ann Smith Mary Wilson The idno is an attribute of donor. The ID means it must be unique. The title is an attribute of name and it can have any one of the titles included in the list. #IMPLIED means that this is an optional attribute. CDATA allows for a large block of text that the XML processors interprets only as text.

15 <![CDATA[ 14 Main St Fall River, MA 02770 ]]> 1996 David Costa Nancy Taylor <![CDATA[ 1 Heritage Rd New Bedford, MA 02775 ]]> 1994 Ann Smith Robert Brooks <![CDATA[ 45 East St Weymouth, MA 02176 ]]> 1996 Roger Brown

16 DONOR DONATION The XML has been set up to have a series of donors and information about the donor and for each donor, one or more donations and information about the donation.

17

18 <!DOCTYPE donors [ ]> John Doe <![CDATA[ 123 Elm St Braintree, MA 02184 ]]> 1995 Ann Smith Donations has been added to the list of elements in donor. Within donation there is room for multiple donations. Each with have a required unique number called donationid, a reference to the donor called given by and the elements date of contribution and amount of contribution.

19 7/5/2000 1200 5/14/2000 500 Mary Wilson <![CDATA[ 14 Main St Fall River, MA 02770 ]]> 1996 David Costa 5/15/2000 500 Nancy Taylor This shows the data for the first donor which includes donation 1 and donation2. For each donation, there are the identifying attributes and the date and amount of the contribution.

20 <![CDATA[ 1 Heritage Rd New Bedford, MA 02775 ]]> 1994 Ann Smith 1/5/2000 1000 2/20/2000 600 1/12/2000 1000 5/5/2000 100 Robert Brooks

21 <![CDATA[ 45 East St Weymouth, MA 02176 ]]> 1996 Roger Brown 1/1/2000 500 5/1/2000 1000 8/1/2000 250


Download ppt "XML and DTD Please you speaker notes for additional information!"

Similar presentations


Ads by Google