Changes

3,120 bytes removed ,  01:14, 6 February 2017
Blanked the page
Line 1: Line 1: −
==[http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node20.html Using the provided XML processing code to get a working parser]==
  −
=== Node -> Element ===
  −
<blockquote>
  −
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:
  −
<code><pre>
  −
Node command = ...;
  −
if (command.getNodeName().equals("createCity"))
  −
// createCity command
  −
</pre></code>
  −
To get the value of an attribute, you could use this code:
  −
<code><pre>
  −
String name = command.getAttribute("name");
  −
</pre></code>
  −
</blockquote>
  −
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 ===
  −
<blockquote>
  −
To ignore comment nodes, you can even do an instanceof check of the command node to make sure it is of type Element.
  −
</blockquote>
  −
instanceof checks can be costly. If there's an alternative, you should use it. That said, Node has a method called [http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html#getNodeType() getNodeType()].
  −
  −
  −
== [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node22.html Outputting XML Conventions] ==
  −
  −
=== Printing to System.out ===
  −
<blockquote>
  −
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.
  −
</blockquote>
  −
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().
  −
  −
== [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node24.html Drawing a spatial map using CanvasPlus] ==
  −
=== Color class ===
  −
It should be noted that all colors used in CanvasPlus refer to their java.awt.Color counterparts.
  −
  −
== [http://www.cs.umd.edu/%7Emeesh/cmsc420/spr07/part1/p11/node26.html Input] ==
  −
=== spatialWidth and spatialHeight ===
  −
<blockquote>
  −
The attributes are spatialWidth and spatialHeight, both Unrestricted Integers...
  −
</blockquote>
  −
spatialWidth and spatialHeight will always be 2<sup>k</sup> by 2<sup>k</sup>. That way you can take advantage of bit operators.
  −
  −
=== List cities ===
  −
<blockquote>
  −
listCities
  −
Prints all cities (vertices) currently present in the graph.
  −
</blockquote>
  −
Graph here means data dictionary.
  −
  −
=== Nearest City tie ===
  −
<blockquote>
  −
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.
  −
</blockquote>
  −
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).
 
editor
32

edits