Class Example6Circle Extends DefaultHandler {
// Local current CIRCLE reference. . .
Private circle
Currentcircle;
// parent ...
ContentHandler Parent;
// XML parser
XmlReader Parser;
// Collect data from the "Characters" SAX event.
Private CharRaywriter Contents = New CharaRrayWriter ();
Public Void CollectCircle (XmlReader Parser,
Contenthandler Parent,
Circle newcircle {
THIS.PARENT = Parent;
This.Parser = Parser;
Parser.SetContentHandler (this);
Currentcircle = newcircle;
}
// Overload
DefaultHandler
Class to intercept
SAX
Method of events.
//
/ / Refer to Org.xml.sax.contenthandler.
//
Public void startElement (String Namespaceuri,
String Localname,
String Qname,
Attributes attr) throws saxception {
CONTENTS.RESET ();
}
Public void endelement (String Namespaceuri,
String Localname,
String Qname) throws saxception {
IF (localname.equals ("x")) {
CurrentCircle.x =
Integer.Valueof
(). Trim ()). INTVALUE ();
}
IF (LocalName.Equals ("y")) {
CurrentCircle.y =
Integer.Valueof
(). Trim ()). INTVALUE ();
}
IF (LocalName.Equals ("width")) {
Currentcircle.width =
Integer.Valueof
(). Trim ()). INTVALUE ();
}
IF (LocalName.Equals ("Height")) {
Currentcircle.height =
Integer.Valueof
(). Trim ()). INTVALUE ();
}
IF (localname.equals ("circalname)) {
// Put the content processor (
Content Handler
Replace
parent
Parser.SetContentHandler (PARENT);
}
}
Public void characters (char [] ch, int start, int ingth)
Throws saxception {
// Collect data from the "Characters" SAX event.
Contents.write (CH, Start, Length);
}}} Class Example 6Square Extends DefaultHandler {
// Current rectangular local reference. . . Private Square
Currentsquare;
// parent ...
ContentHandler Parent;
// XML parser
XmlReader Parser;
// Collect data from the "Characters" SAX event.
Private CharRaywriter Contents = New CharaRrayWriter ();
Public Void CollectSquare (XmlReader Parser,
Contenthandler Parent,
Square newsquare) {
THIS.PARENT = Parent;
This.Parser = Parser;
Parser.SetContentHandler (this);
Currentsquare = newsquare;
}
// Overload
DefaultHandler
Class to intercept
SAX
Method of events.
//
/ / Refer to Org.xml.sax.contenthandler.
//
Public void startElement (String Namespaceuri,
String Localname,
String Qname,
Attributes attr) throws saxception {
CONTENTS.RESET ();
}
Public void endelement (String Namespaceuri,
String Localname,
String Qname) throws saxception {