Hi,

you need to print the qualified name, the qname argument in the startElement
method

Regards,
Pavitra Jain

-----Original Message-----
From: cyril vidal [mailto:[EMAIL PROTECTED]
Sent: Friday, May 03, 2002 4:51 PM
To: [EMAIL PROTECTED]
Subject: SAX problems


Dear all,

I'm new in JAXP's world and I have some problems with an example of tutorial
that perhaps some of you know
(explained by Nicholas Chase on IBM developerWorks
http://www-106.ibm.com/developerworks/education/xmljava
)
I run under JAVA 2 SDK Standard Edition version 1.3.0
and Xalan-JAVA 2 that builds on JAXP1.0 (itself including xercesImpl.jar).
Here's my problem. In the following code, the startElement method returns a
null value for the name of the element instead of the real value and I
definetively don't understand why.
SOme of you could help me, please?
Do I have to install an other version of Xerces or a Jaxp RI so that it can
runs correctly?
heres's the code:
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;




public class exemple
                    extends DefaultHandler
{

   public exemple() {
   }

    public void error (SAXParseException e) {
      System.out.println("Error parsing the file: "+e.getMessage());
   }

   public void warning (SAXParseException e) {
      System.out.println("Problem parsing the file: "+e.getMessage());
   }

   public void fatalError (SAXParseException e) {
      System.out.println("Error parsing the file: "+e.getMessage());
      System.out.println("Cannot continue.");
      System.exit(1);
   }

   public void startDocument()
                   throws SAXException {
      System.out.println(
                    "Tallying survey results...");
   }


   public void startElement(
                String namespaceURI,
                String localName,
                String qName,
                Attributes atts)
                   throws SAXException {

       System.out.print("Start element: ");
       System.out.println(localName);//return null!??


    for (int att = 0;
         att < atts.getLength();
         att++) {
       String attName = atts.getLocalName(att);
       System.out.println("   "
                     + attName + ": "
                     + atts.getValue(attName));
   }
  }



   public static void main (String args[]) {

      XMLReader xmlReader = null;

      try {

         SAXParserFactory spfactory =
             SAXParserFactory.newInstance();
         spfactory.setValidating(false);


         SAXParser saxParser =
                   spfactory.newSAXParser();

         xmlReader = saxParser.getXMLReader();
         xmlReader.setContentHandler(new exemple());
         xmlReader.setErrorHandler(new exemple());
         InputSource source =
                     new InputSource("surveys.xml");
    xmlReader.parse(source);



      } catch (Exception e) {
            System.err.println(e);
            System.exit(1);
      }
   }



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


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

Reply via email to