Difference between revisions of "Spec 1.1 Errata"

From CMSC 420
Line 23: Line 23:
  
 
== [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node22.html Outputting XML Conventions] ==
 
== [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node22.html Outputting XML Conventions] ==
 
=== Error tag typo ===
 
<blockquote>
 
General <error> Output
 
 
    This is the form (in the exact output order) of a general <error> tag. The <parameters> tag will always be present even if there are no parameters to the command. In each command there may be several errors listed if several errors occur in a command you will only output the error of highest priority. For more information see XML Input specification for each command.
 
<code><pre>
 
    <error type="error1">
 
        <command name="name1"/>
 
        <parameters>
 
            <param1 value="value1"/>
 
            <param2 value="value2"/>
 
        </parameters>
 
    <error/>
 
</pre></code>
 
</blockquote>
 
The last tag should be </error>, not <error/>.
 
  
 
=== Printing to System.out ===
 
=== Printing to System.out ===

Revision as of 01:08, 6 February 2017

Using the provided XML processing code to get a working parser[edit]

Node -> Element[edit]

In the DOM, every XML object implements the org.w3c.dom.Node interface. Nodes have a lot of useful methods, but the ones you care most about are getNodeName(), getNodeValue(), and getAttribute(). Suppose you had a Node object representing one of our command elements. You could determine which command it was with the following code:

Node command = ...;
if (command.getNodeName().equals("createCity"))
// createCity command

To get the value of an attribute, you could use this code:

String name = command.getAttribute("name");

If you read the Java API, you'll see both Document and Element are subtypes of Node. A Node does not have the method getAttribute(). But Element does have a getAttribute() method.

Node Child List[edit]

To ignore comment nodes, you can even do an instanceof check of the command node to make sure it is of type Element.

instanceof checks can be costly. If there's an alternative, you should use it. That said, Node has a method called getNodeType().


Outputting XML Conventions[edit]

Printing to System.out[edit]

It is sufficient to merely spit these out to System.out (the standard output stream) as they are discovered when processing the commands. However, remember that the result must be a well-formed XML document and a well-formed XML document must have a single root element.

Do not call System.out.println() to print out your output. Instead, create a new Document and append Elements to it as you process commands. You can print a Document to System.out using XmlUtility.print().

Output schema?[edit]

(You may want also to stick an <?xml version="1.0" ?> tag in the front (JAXP XML outputters will usually insert it in for you). So in other words, you don't need to worry about building a DOM object, since we'll expect you to just print it to the standard out anyway. We will test your output XML by feeding it into our XML parser, validating it against our schema, and then reprinting the DOM object we create, and diffing the results. After we standardize your output by building it into a DOM object and rewriting it to a stream, our XML and your XML should look exactly the same.

We do not have an output schema. Make sure that your output matches the spec requirements.

Drawing a spatial map using CanvasPlus[edit]

Color class[edit]

It should be noted that all colors used in CanvasPlus refer to their java.awt.Color counterparts.

Input[edit]

spatialWidth and spatialHeight[edit]

The attributes are spatialWidth and spatialHeight, both Unrestricted Integers...

spatialWidth and spatialHeight will always be 2k by 2k. That way you can take advantage of bit operators.

List cities[edit]

listCities Prints all cities (vertices) currently present in the graph.

Graph here means data dictionary.

Nearest City tie[edit]

nearestCity Will return the name and location of the closest city to the specified point in space. To do this correctly, you may want to use the PriorityQueue-otherwise, you might not be fast enough.

If there is a distance tie, check the city names using java.lang.String.compareTo() (for a distance tie, the nearestCity name is less than the other city name).