|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface XMLConsumer
Interface of an XML event consumer. Rq: This interface has been inspired by SAX interface. The only difference is that the tag parameter are memorized in a java Hashtable object instead of the AttrList SAX object. Example of usage :
import cds.xml.*; import java.io.*; import java.util.*; // Simple class to test the XML parser. // Usage: java ParseDemo file.xml public class ParseDemo implements XMLConsumer { XMLParser xp; // Creat and launch the XML parsing ParseDemo(DataInputStream dis) { xp = new XMLParser(this); if( !xp.parse(dis) ) System.err.println( xp.getError() ); } // Method called for each start XML tag public void startElement(String name, Hashtable atts) { System.out.println("Begins tag: "+name); Enumeration e = atts.keys(); while( e.hasMoreElements() ) { String s = (String)e.nextElement(); System.out.println(" ."+s+" = "+(String)atts.get(s) ); } if( xp.in("RESOURCE TABLE") ) System.out.println("==> in RESOURCE TABLE"); } // Method called for each end XML tag public void endElement(String name) { System.out.println("Ends tag: "+name); } // Method called to send the contain of the current XML tag public void characters(char [] ch, int start, int lenght) { System.out.println("tag contain: ["+ (new String(ch,start,lenght)) +"]"); } // The main method to test it static public void main(String [] arg) { try { // Open the first arg as a file DataInputStream dis = new DataInputStream( new FileInputStream(arg[0])); // Parse the file new ParseDemo(dis); } catch( Exception e ) { System.err.println("There is a problem: "+e); e.printStackTrace(); } } }
Method Summary | |
---|---|
void |
characters(char[] ch,
int start,
int length)
This method is called by the XML parser to transmit the contain of the current XML tag (ex: <TAG> ... the contain ... |
void |
endElement(java.lang.String name)
This method is called by the XML parser when it reaches an end XML tag (ex: </TAGNAME> or <TAGNAME .../>) |
void |
startElement(java.lang.String name,
java.util.Hashtable atts)
This method is called by the XML parser when it reaches an XML tag (ex: <TAGNAME paramname=paramvalue ...>) Rq: For the specials tags <TAGNAME .../>, this method is always called before the endElement() in order to transmit the eventual parameters. |
Method Detail |
---|
void startElement(java.lang.String name, java.util.Hashtable atts)
name
- The tag name (TAGNAME in the example)atts
- The tag parameters in an Hashtable. The keys of the
hashtable are the param name.void endElement(java.lang.String name)
name
- The tag name (TAGNAME in the example)void characters(char[] ch, int start, int length) throws java.lang.Exception
ch
- The array of charstart
- the index of the first characterlength
- the length of the contain
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |