cds.xml
Interface XMLConsumer

All Known Implementing Classes:
LocalServer, TableParser, VizieRQuery

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();
       }
    }
 }
 

Version:
1.0 3 sep 99 Creation
Author:
P.Fernique [CDS]

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

startElement

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.

Parameters:
name - The tag name (TAGNAME in the example)
atts - The tag parameters in an Hashtable. The keys of the hashtable are the param name.

endElement

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 .../>)

Parameters:
name - The tag name (TAGNAME in the example)

characters

void characters(char[] ch,
                int start,
                int length)
                throws java.lang.Exception
This method is called by the XML parser to transmit the contain of the current XML tag (ex: <TAG> ... the contain ... </TAG>) Rq: To know the tag name associated, the XML parser implements the Stack getStack() method. This stack is formed by the list of hierarchical tag names

Parameters:
ch - The array of char
start - the index of the first character
length - the length of the contain
Throws:
java.lang.Exception


Copyright © 2009 UDS/CNRS