XML Exercise 4
Document Type Definition

Advanced Web Development • 152-121

Requirements

Add a DTD for the Inventory XML document used in Exercise 3.

  1. Add a DTD to the document

    Add an internal DTD to validate the Inventory XML document. It should validate the following:

    1. The root element Items should have one or more item entries (minimum of one).

    2. The ItemNumber attribute should be defined as an ID and is required.

    3. Backordered Amount attribute, Date Ordered is optional (does not have to be present). It would only be present if there was a value other than 0 (zero) in the document.

    4. There may be one or more Supplier (a minimum of one Supplier)

    5. The Selling Price attribute, SaleItem, must be either a Y or N to be valid

    6. The Shipment Lead time attribute called Unit must be either days or weeks

    7. All other data is PCDATA.

    8. Add an element below the <Description> element. The new element should be called <Country>. This element represents the country that the product has been manufactured in. Add the following entities to the DTD and use the entities in the country element to display the actual entity text. Make sure that you use only the entity reference between the <Country> and closing </Country> tags. Note: you have "artistic license" to add additional countries of your choice if you wish.

    Entity Reference Text that should display
    &us; Made in the United States
    &ch; Made in China
    Made in India
    &sa; Made in South Africa
    &jp; Made in Japan
    &bz; Made in Brazil
    &gr; Made in Germany

     

    Inventory XML Document

    Items
        Item ItemNumber=""
           Description
           Country
           SellingPrice SaleItem=""
           Cost 
           Quantity On Hand 
           Backordered Amount dateOrdered="mmddyyyy"
           Date Last Received 
               Month 
               Day 
               Year
           Quantity Sold Year-To-Date 
           Warehouse Section 
           Warehouse Shelve 
           Remarks
           Supplier
               Number 
               ShipmentLeadTime unit=""
               Cost
           Supplier
               Number 
               ShipmentLeadTime unit=""
               Cost
Item ItemNumber="" Description Country Selling Price saleItem="" Cost Quantity On Hand Backordered Amount Date Last Received Month Day Year Quantity Sold Year-To-Date Warehouse Section Warehouse Shelve Remarks Supplier Number ShipmentLeadTime unit="" Cost Supplier Number ShipmentLeadTime unit="" Cost

Steps

  1. Add the Country element (without any content) after Description

  2. After the XML declaration, add the following code:

    <!DOCTYPE Items [

  3. Next add the definition for the Items element. Be sure to include notation for more than one supplier:

    <!ELEMENT Item (Description, Country, SellingPrice, - continue including other elements here )>

  4. Define each primitive element:

    <!ELEMENT Description (#PCDATA)>

    Continue including other elements here

  5. Define the parent element of Date Last Received containing child elements: Month, Day and Year, then define Month, Day and Year as #PCDATA

  6. Define the parent element of Supplier containing child elements: Number, Shipment Lead Time and Cost, then define Number, Shipment Lead Time and Cost as #PCDATA

  7. Add the entity definitions in the DTD listed in the table in Point H above. Put an entity reference (use &countrycode; format) for one country in each Country tag.

  8. Next define the ATTLIST statements. Define ItemNumber as an ID, required; then continue to define the other attributes.

  9. Test the document to see if it validates.

  10. Make any changes, and when the document is valid, demonstrate it to your instructor.