Java Reference
In-Depth Information
That's all the code we need. You now need to make sure all the imports are in place for the source files
we have modified. In addition to what was already there, the
Element.java
file needs:
import org.w3c.dom.Document;
import org.w3c.dom.Attr;
The
SketchFrame.java
file needs the following
import
statements added to the original set:
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
You should also have added the following imports to the
SketchModel.java
file:
import javax.swing.JOptionPane;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.DOMException;
If everything compiles, you are ready to try exporting and importing sketches.
Try It Out- Sketches in XML
You can try various combinations of elements to see how they look in XML. Be sure to copy the
sketcher.dtd
file to the directory in which you are storing exported sketches. If you don't, you won't
be able to import them since the DTD will not be found. Don't forget you can look at the XML using
any text editor and in most browsers. I created the sketch below.