All pastes #254242 Raw Edit

7 moi

public text v1 · immutable
#254242 ·published 2006-11-21 17:29 UTC
rendered paste body
// ------------------------------- Client.java ------------------------------
/** Package modmission regroupe les classes du modele. **/
//on importe les API necessaires
//pour l'analyse du XML
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
//pour l'acces aux fichiers
import java.io.*;

public class essai extends DefaultHandler
{
	 public static void main(String[] args) throws IOException
	 {
		//on lance l'analyseur avec le fichier XML en parametre
		DefaultHandler handler = new essai();
		SAXParserFactory factory = SAXParserFactory.newInstance();
		try 
		{
			SAXParser saxParser = factory.newSAXParser();
			saxParser.parse( new File("client.xml"), handler );
		} 
		catch (Throwable t) 
		{
		//Si on a une erreur pendant l'analyse
		t.printStackTrace ();
		System.exit (1);
		}
	}		
		
	  public void error(SAXParseException e) throws SAXParseException{
		throw e;
	}
	private String idClient;
	private String Nom;
	public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException
	{
			String eName = localName,rang=null,nom=null,score=null;
			if("".equals(eName))
			{ 
				eName = qName;
			}			
			if(attrs != null && eName == "client")
			{
				for(int i = 0; i < attrs.getLength(); i++)
				{
					String aName = attrs.getLocalName(i);
					if(attrs.getQName(i) == "idClient")
					{ 
						idClient = attrs.getValue(i);
						System.out.println(idClient);
					}
					if(attrs.getQName(i) == "nom")
					{ 
						Nom = attrs.getValue(i); 
						System.out.println(Nom);
					}
				}
			}
	}
}//fin class Client