000419-2

You are designing a protocol for sending ratings of web pages to a data base. Each submission contains information about the rater (e-mail address, competence), identification of a document through its URI, and a series of values which rates the document according to different scales, such as readability, newsvalue, correctness, suitability-for-minors. Rater-competence can be amateur or expert. Write a DTD for this. Use XML attributes when suitable.

Answer

DTD:

<!ELEMENT send-rating (atomic-rating+)>
<!ELEMENT atomic-rating (rating-value+)>
<!ATTLIST atomic-rating
rater-email CDATA #REQUIRED
location CDATA #REQUIRED
rater-competence ( amateur | expert | un-known ) 'un-known'
>
<!ELEMENT rating-value EMPTY>
<!ATTLIST rating-value
type
( readability | newsvalue | correctness |
suitability-for-minors | un-known ) 'un-known'
value CDATA #REQUIRED >

XML example (not required):

<?xml version="1.0" ?>
<!DOCTYPE send-rating SYSTEM
"http://dsv.su.se/jpalme/internet-course/xml/send-rating.dtd">
<send-rating>
<atomic-rating
rater-email="jpalme@dsv.su.se"
location="http://www.body.com/eyes"
rater-competence="amateur">
<rating-value
type="readability"
value="good"/>
<rating-value
type="newsvalue"
value="bad"/>
</atomic-rating></send-rating>

Note 1:

"type CDATA #REQUIRED" would be equally good, maybe better, since it allows new types of ratings without changes in the DTD.

Note 2:

Since the question specified "Use XML attributes when suitable", a solution with sub-elements instead of attributes does not fully agree with the question. Thus, the following solution does not give full scores on this question:

DTD (not correct answer):

<!ELEMENT send-rating2 (atomic-rating+) >
<!ELEMENT atomic-rating (rater-email, location, rater-competence, rating-value+ ) >
<!ELEMENT rater-email (#PCDATA) >
<!ELEMENT location (#PCDATA) >
<!ELEMENT rater-competence (#PCDATA) >
<!ELEMENT rating-value (type, value) >
<!ELEMENT type (#PCDATA) >
<!ELEMENT value (#PCDATA) >

XML example (not correct answer):

<?xml version="1.0" ?>
<!DOCTYPE send-rating2 SYSTEM
"http://dsv.su.se/jpalme/internet-course/xml/send-rating2.dtd">
<send-rating2>
<atomic-rating>
<rater-email>jpalme@dsv.su.se</rater-email>
<location>http://www.body.com/eyes</location>
<rater-competence>amateur</rater-competence>
<rating-value>
<type>readability</type>
<value>good</value></rating-value>
<rating-value>
<type>news-value</type>
<value>bad</value></rating-value>
</atomic-rating></send-rating2>

List of exam questions