Chapter 5:
XML: A Standard Representation for Specifications
Summary
XML is a standard language for representing structured information. Although it is used primarily in the context of Internet applications and communications, it can also be used for expressing the specification input to a program generator. The essence of XML is the separation of abstract content from presentation. In the context of program generators it is used to separate "what" application you want from the software that implements the program.
XML has elements and attributes. In adapting a set of variabilities to XML, one must decide whether and how to use attributes for what pieces of information. There is no clear-cut method for making these decisions, but this chapter provides some general guidelines for making such decisions. The chapter explains and defines an XML document type for the Play domain.
A major advantage of using XML is the range of XML tools that can be applied. These include viewers, editors, and translators.
Chapter 1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13
Example 5-8: Standard Example Play Specification
Example 5-9: DTD for the Play Domain (Phase 1)
Example 5-14: DTD for the Play Domain (Phase 2)
Example 5-8: Standard Example Play Specification
<?xml version="1.0" standalone="no"?>
<!DOCTYPE play SYSTEM "file:play1.dtd">
<play name="JackAndJill" width="300" height="120" start="bottom">
<title>Jack and Jill</title>
<prop name="up">
<trait>Go up the hill</trait>
<script goto="top">
<trait prop="fetch">Fetch a pail of water</trait>
</script>
</prop>
<prop name="fetch">
<trait>Fetch a pail of water</trait>
<script><trait>Fetch another pail</trait></script>
</prop>
<prop name="fall">
<trait>Fall down, break crown</trait>
<script goto="bottom">
<trait>Break crown</trait>
<trait prop="tumble">Tumble after</trait>
</script>
</prop>
<prop name="tumble">
<trait>Tumble down</trait>
<script goto="bottom"/>
</prop>
<scene name="bottom" color="#8888aa">
<addprop name="up"/>
<addprop name="fall"/>
</scene>
<scene name="top">
<addprop name="fetch"/>
<addprop name="fall"/>
<addprop name="tumble"/>
</scene>
</play>
|
Example 5-9: DTD for the Play Domain (Phase 1)
<!ELEMENT play (title, prop*, scene*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT prop (trait|script)*>
<!ELEMENT scene (addprop*)>
<!ELEMENT trait (#PCDATA)>
<!ELEMENT script (trait*)>
<!ELEMENT addprop EMPTY>
<!ATTLIST play width CDATA "500">
<!ATTLIST play height CDATA "250">
<!ATTLIST play name ID #REQUIRED>
<!ATTLIST play start IDREF #REQUIRED>
<!ATTLIST prop name ID #REQUIRED>
<!ATTLIST addprop name IDREF #REQUIRED>
<!ATTLIST trait name CDATA "Label">
<!ATTLIST trait prop IDREF #IMPLIED>
<!ATTLIST scene name ID #REQUIRED>
<!ATTLIST scene color CDATA "#dddddd">
<!ATTLIST script goto IDREF #IMPLIED>
|
Example 5-14: DTD for the Play Domain (Phase 2)
<!ELEMENT play (title, prop*, scene*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT prop (trait|code|script)*>
<!ELEMENT scene (addprop*)>
<!ELEMENT trait (#PCDATA|string|color|code)*>
<!ELEMENT script (code|trait)*>
<!ELEMENT code (#PCDATA)>
<!ELEMENT addprop (script)*>
<!ELEMENT color (#PCDATA)>
<!ELEMENT string (#PCDATA)>
<!ATTLIST play width CDATA "500">
<!ATTLIST play height CDATA "250">
<!ATTLIST play name ID #REQUIRED>
<!ATTLIST play start IDREF #REQUIRED>
<!ATTLIST prop name ID #REQUIRED>
<!ATTLIST prop type CDATA "Button">
<!ATTLIST addprop name IDREF #REQUIRED>
<!ATTLIST trait name CDATA "Label">
<!ATTLIST trait prop IDREF #IMPLIED>
<!ATTLIST scene name ID #REQUIRED>
<!ATTLIST scene color CDATA "#dddddd">
<!ATTLIST script goto IDREF #IMPLIED>
<!ATTLIST script event CDATA "Action">
<!ATTLIST script method CDATA "actionPerformed">
<!ATTLIST code language CDATA "Java">
|