View Single Post
  #12 (permalink)  
Old 01-07-2008, 01:14 PM
Preethi Preethi is offline
Member
 
Join Date: Jan 2008
Posts: 83
Rep Power: 0
Preethi is on a distinguished road
Default
Yes,even then its not initiated...
This is my class where i add to the list;
Code:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public  class NewClass extends DefaultHandler
{
    public static List list;
    private String tempVal;
    
    //Creating a reference for Class nodes
    private nodes tempnode;
    public static Iterator it;
   
    
    public NewClass()
    {
        list = new ArrayList();
        it = list.iterator();
    }
    
    public void runExample() 
    {
        parseDocument();
        printData();
    }

    private void parseDocument() 
    {
       /** Reads the file**/
    }

    public static List printData()
    {
        System.out.println("No of Employees '" + list.size() + "'.");
        it = list.iterator();
        while(it.hasNext()) 
        {
            System.out.println(it.next());
        }
        return list;
    }
    
   
    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException 
    {
    //reset
        tempVal = "";
        if(qName.equalsIgnoreCase("res_mesg")) 
        {
            //create a new instance of employee
            tempnode = new nodes();
            for(int len=0;len<attributes.getLength();len++)
            {
                tempnode.setcategory(attributes.getType("category"));
            }
        }
    }
    public void characters(char[] ch, int start, int length) throws SAXException    
    {
        tempVal = new String(ch,start,length);
    }

    public void end(String uri, String localName, String qName) 
    {
        if(qName.equalsIgnoreCase("res_mesg")) 
        {
            
            //add it to the list
            list.add(tempnode);

        }
        else if (qName.equalsIgnoreCase("res_no")) 
        {

            tempnode.setresno(tempVal);
            
        }
    }
    public static void main(String[] args)  
    {
        NewClass spe = new NewClass();
        spe.runExample();
       
    }
   
}
Reply With Quote