| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 
 |  
 
HistoriqueFinancier historiqueFin = new HistoriqueFinancier();
try{
	// création d'une fabrique de documents
DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
 
// création d'un constructeur de documents
DocumentBuilder constructeur = fabrique.newDocumentBuilder();
 
// lecture du contenu d'un fichier XML avec DOM
File xml = new File("./histov2.xml");
Document document = constructeur.parse(xml);
 
//traitement du document
Element racine = document.getDocumentElement();
NodeList nodeList = racine.getChildNodes();
for(int i=0; i<nodeList.getLength(); i++){
	Node n = nodeList.item(i);
	if(n.getNodeName().compareTo("Poste")==0){
		String posteLabel = n.getAttributes().item(0).getTextContent();
		historiqueFin.ajouterUnPoste(posteLabel);
		//System.out.println("Poste : "+posteLabel);
		NodeList nodeList2 = n.getChildNodes();
		for(int j=0; j<nodeList2.getLength(); j++){
			Node n2 = nodeList2.item(j);
			if(n2.getNodeName().compareTo("Mouvement")==0){
				//System.out.println("MOUVEMENT !!! ");
				NodeList nodeList3 = n2.getChildNodes();
				String dateMvt = nodeList3.item(1).getTextContent();
				String typeMvt = nodeList3.item(3).getTextContent();
				String montantMvt = nodeList3.item(5).getTextContent();
				//System.out.println("Date : "+dateMvt);
				//System.out.println("Type : "+typeMvt);
				//System.out.println("Montant : "+montantMvt);
				// FAIRE UN MOUVEMENT DS L HISTO FINANCIER
				Date dateMvt_Date=null;
				try {
					dateMvt_Date= InterfaçageSauvegarde.dateFormat.parse(dateMvt);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(typeMvt.compareTo("Dépôt")==0){
					historiqueFin.recevoirSommePour(Integer.parseInt(montantMvt), posteLabel,dateMvt_Date);
				}else if(typeMvt.compareTo("Retrait")==0){
						historiqueFin.depenserSommePour(Integer.parseInt(montantMvt), posteLabel,dateMvt_Date);
					}
 
				}
			}
		}
	}
 
 
}catch(ParserConfigurationException pce){
	System.out.println("Erreur de configuration du parseur DOM");
System.out.println("lors de l'appel à fabrique.newDocumentBuilder();");
}catch(SAXException se){
	System.out.println("Erreur lors du parsing du document");
System.out.println("lors de l'appel à construteur.parse(xml)");
}catch(IOException ioe){
	System.out.println("Erreur d'entrée/sortie");
System.out.println("lors de l'appel à construteur.parse(xml)");
} | 
Partager