import java.io.*; import org.xml.sax.*; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.*; public class Exemple{ // args[0] contient un nom de fichier d'un document XML public static void main(String[] args){ // le producteur XMLReader prod; // le consommateur DefaultHandler cons; try { //obtenir un parser prod = XMLReaderFactory.createXMLReader(); } catch (SAXException e){ System.err.println("pbe de configuration"); return; } try { //et un consommateur qui ne fait pas grand chose cons = new MonContentHandler(); prod.setContentHandler(cons); prod.setErrorHandler(cons); } catch (Exception e){ System.out.println("il y a eu un souci"); return; } // et c'est parti! try { prod.parse(new InputSource(new FileReader(args[0]))); } catch(IOException e){ System.out.println("pbe d'entree-sortie"); return; } catch(SAXException e){ System.out.println("pbe du parseur"); return; } } }