Here are the answers to the two exercises I gave you in this chapter. Attribute ListThe first exercise was to write an element line given an attribute declaration. Attribute declaration: <!ATTLIST PERSON PERSONID CDATA> Element line: <PERSON PERSONID="176"> The value of the attribute can be any type of character data. Attribute declaration: <!ATTLIST EMPLOYEE MALE (truefalse "true"> Element line: <EMPLOYEE MALE="false"> The MALE attribute can be either true or false . If it isn't explicitly declared, it defaults to true . Attribute declaration: <!ATTLIST EMPLOYEE STATUS (singlemarrieddivorcedwidowed) #REQUIRED> Element line: <EMPLOYEE STATUS="divorced"> The STATUS attribute can be one of four possible values, as specified in the attribute list. The attribute must be present and specified. Invalid XML DocumentThe second exercise was to identify the problems with the XML document shown in Listing 1.22. Listing 1.22 Incorrect XML Document<?xml version="1.0 standalone="no"?> <!DOCTYPE VENDORS [ <!ELEMENT VENDORS (VENDOR)?> <!ELEMENT (NAME, LOCATION, BUSINESS, DIVISION+)> <!ATTLIST DIVISION NAME CDATA #REQUIRED BUDGET CDATA #IMPLIED > <!ELEMENT NAME (#PCDATA)> <!ELEMENT LOCATION (#PCDATA)> <!ELEMENT BUSINESS (#PCDATA)> <!ELEMENT DIVISION (#PCDATA)> <!ELEMENT LOCATION (STREET, CITY, STATE, ZIP)> <!ATTLIST ZIP CDATA #REQUIRED> <!ELEMENT STREET (#PCDATA)> <!ELEMENT CITY (#PCDATA)> <!ELEMENT STATE (#PCDATA)> <!ELEMENT ZIP (#PCDATA)> ] <VENDORS xmlns:vend='http://www.myorg.com/companytags'> <VENDOR> <NAME>Iomega</NAME> <LOCATION> <STREET>1821 W.Iomega</STREET> <comment -- this is a test file--> <CITY>Roy</CITY> <STATE>UT</STATE> <ZIP SUB="8441">84067 </LOCATION> <BUSINESS>Manufacturing</BUSINESS> <DIVISION NAME="Sales" BUDGET="350000"> </DIVISION> <DIVISION NAME="IT" BUDGET="650000"> </DIVISION> <DIVISION NAME="HR" BUDGET="650000"> </DIVISION> </VENDOR> <VENDOR> <NAME>Dell</NAME> <LOCATION> <STREET>1000 W. Addison</STREET> <CITY>Dallas</CITY> <STATE>TX</STATE> <ZIP SUB="3456">40078 </LOCATION> <BUSINESS>Computer Manufacturing</BUSINESS> <DIVISION NAME="Sales" BUDGET="650000"> </DIVISION> <DIVISION NAME="IT" BUDGET="750000"> </DIVISION> <DIVISION NAME="HR" BUDGET="1650000"> </DIVISION> </VENDOR> </VENDORS> Here is the list of corrections needed to make this a valid, well- formed XML document and schema.
|