XML and DTD Please you speaker notes for additional information!
<!DOCTYPE customer [ ]> Susan Ash 12 Elm St Braintree MA 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.
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.
<!DOCTYPE customers [ ]> Susan Ash 12 Elm St Braintree MA Stephen Daniels 45 East St Brooklyn NY 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).
Customers Fall River Store 112 Main Street Fall River, MA Customer Id: Name: Address: City: State: Zip:
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
<!DOCTYPE customers [ ]> Susan Ash 12 Elm St Braintree MA Stephen Daniels 45 East St Brooklyn NY 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.
<!DOCTYPE customers [ ]> Susan Ash 12 Elm St Braintree MA Stephen Daniels 45 East St Brooklyn NY 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:
<!DOCTYPE donors [ <!ELEMENT donor(name, address, yrfirst?, contact?) <!ELEMENT name (#PCDATA) ]> John Doe <![CDATA[ 123 Elm St Braintree, MA ]]> 1995 Ann Smith
<!DOCTYPE donors [ <!ELEMENT donor(name, address, yrfirst?, contact?) <!ELEMENT name (#PCDATA) ]> John Doe <![CDATA[ 123 Elm St Braintree, MA ]]> 1995 Ann Smith Need the > at the end.
<!DOCTYPE donors [ ]> John Doe <![CDATA[ 123 Elm St Braintree, MA ]]> 1995 Ann Smith
<!DOCTYPE donors [ ]> John Doe <![CDATA[ 123 Elm St Braintree, MA ]]> 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.
<![CDATA[ 14 Main St Fall River, MA ]]> 1996 David Costa Nancy Taylor <![CDATA[ 1 Heritage Rd New Bedford, MA ]]> 1994 Ann Smith Robert Brooks <![CDATA[ 45 East St Weymouth, MA ]]> 1996 Roger Brown
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.
<!DOCTYPE donors [ ]> John Doe <![CDATA[ 123 Elm St Braintree, MA ]]> 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.
7/5/ /14/ Mary Wilson <![CDATA[ 14 Main St Fall River, MA ]]> 1996 David Costa 5/15/ 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.
<![CDATA[ 1 Heritage Rd New Bedford, MA ]]> 1994 Ann Smith 1/5/ /20/ /12/ /5/ Robert Brooks
<![CDATA[ 45 East St Weymouth, MA ]]> 1996 Roger Brown 1/1/ /1/ /1/