Write a Java application that loads an XML document that contains the DTD in Fig. 8.19 as part of its internal subset. Use the XML document’s data to draw rectangles and circles with text inside them. Attributes x and y represent the top-left coordinates. Assume a circle is bounded by an imaginary rectangle. Attributes width and height represent the rectangle’s width and height and attribute radius is the circle’s radius. Validate your XML document(s) against the DTD.

```
1 2
3
4 5 y CDATA #REQUIRED
6 width CDATA #REQUIRED
7 height CDATA #REQUIRED>
89

10 11 y CDATA #REQUIRED
12 radius CDATA #REQUIRED>
13 ]>
```


```

3

4 import java.awt.*;

5 import java.awt.event.*;

6 import javax.swing.*;

7 import java.io.*;

8

9import org.w3c.dom.*;

10 import org.xml.sax.*;

11 import javax.xml.parsers.*;

12 import com.sun.xml.tree.XmlDocument;

13

14 public class DrawShapes extends JFrame {

15 private InputSource input;

16 private Document document;

17

18 public DrawShapes( String file )

19 {

20 super( "My new drawing Application." );

21

22 try {

23

24 // obtain the default parser

25 DocumentBuilderFactory factory =

26 DocumentBuilderFactory.newInstance();

27 factory.setValidating( true );

28 DocumentBuilder builder = factory.newDocumentBuilder();

29

30 // set error handler for validation errors

31 builder.setErrorHandler( new MyErrorHandler() );

32

33 // obtain document object from XML document

34 document = builder.parse( new File( file ) );

35 }

36 catch ( SAXParseException spe ) {

37 System.err.println(

38 "Parse error: " + spe.getMessage() );

39 Sy

Computer Science & Information Technology

You might also like to view...

Explain how wireless LANs are beneficial to both teachers and students in an educational setting.

What will be an ideal response?

Computer Science & Information Technology

The ________ paste option will cause pasted text to match the formatting in your document

A) Keep Text Only B) Merge Formatting C) Unformatted Text D) Keep Source Formatting

Computer Science & Information Technology

You can run an attended installation process for a clean installation of Windows 8.1, but not for an upgrade

Indicate whether the statement is true or false

Computer Science & Information Technology

Provide three examples of an application where menu selection and form fill-in are more appropriate than a direct-manipulation strategy.

What will be an ideal response?

Computer Science & Information Technology