You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by cyril vidal <cy...@wanadoo.fr> on 2002/05/03 14:19:39 UTC

RE: SAX problems

Thanks a lot!
It runs now. But why should I do this? In my xml file, ther's no namespace...
Is there any explication?
Thanks
Cyril

> 
> -----Original Message-----
> From: cyril vidal [mailto:cyr.vidal@wanadoo.fr]
> Sent: Friday, May 03, 2002 4:51 PM
> To: xerces-j-user@xml.apache.org
> 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: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org