Thanks a lot Arun. I need one more help. xml file

- <Library>
- <Book>
  <Title>Professional JINI</Title> 
  <Author>Sing Li</Author> 
  <Publisher>Wrox Publications</Publisher> 
  </Book>
- <Book>
  <Title>XML Programming</Title> 
  <Author>Sudhir Ancha</Author> 
  <Publisher>Mann Publications</Publisher> 
  </Book>
  </Library>

in this xml, first I want to verify author 'Sing Li'. If the 
parser does not find the author node with value 'Sing Li', 
then it should print some message or error. if it finds that 
then I want to verify publisher 'Mann Publications. if it 
exists then some message , if it doesn't then error.

code is 

import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.ParserAdapter;

public class MySAXApp extends DefaultHandler
{

    public static void main (String args[])
        throws Exception
    {

        
        XMLReader xr =XMLReaderFactory.createXMLReader
("org.apache.xerces.parsers.SAXParser"); 
        MySAXApp handler = new MySAXApp();
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);

           FileReader r = new FileReader("zzz.xml");
            xr.parse(new InputSource(r));
    }


    public MySAXApp ()
    {
        super();
    }
  

    public void startDocument ()
    {
        System.out.println("Start document");
    }


    public void endDocument ()
    {
        System.out.println("End document");
    }


    public void startElement (String uri, String name,
                              String qName, Attributes atts)
    {
        if(!(name.equals("author")))
        break;
        System.out.println("Start element: " + name);
        
    }


    public void endElement (String uri, String name, String 
qName)
    {
        System.out.println("End element: "   + name);
    }


    public void characters (char ch[], int start, int length)
    {
        
        for (int i = start; i < start + length; i++) {
                System.out.print(ch[i]);

        }

    }

}

Thanks
vijay

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to