1 2 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| package pk1;
import java.io.*;
import org.jdom.*;
import org.jdom.input.*;
import java.util.Iterator;
import java.util.List;
public class TableauXml
{ static String tab[]=new String[100];
static int e=0;
static org.jdom.Document document;
static Element racine;
public static void main(String[] args)
{
//On crée une instance de SAXBuilder
SAXBuilder sxb = new SAXBuilder();
try
{
//On crée un nouveau document JDOM avec en argument le fichier XML
//Le parsing est terminé ;)
document = sxb.build(new File("Fichier_description.xml"));
}
catch(Exception e){}
//On initialise un nouvel élément racine avec l'élément racine du document.
racine = document.getRootElement();
//initialisation_tableau();
parcourFichier();
//afficherTab();
ajouter("C2","6","7","8");
// afficherTab();
//supprimer("5","6","7","8");
//afficherTab();
maj();
}
public static void initialisation_tableau()
{
for(int f=0;f<tab.length;f++)
tab[f]="";
}
static void maj()
{
for(int k=0;k<tab.length;k=k+4)
if(tab[k]!=null)
FichierDescriptionMachine.remplir(tab[k],tab[k+1],tab[k+2],tab[k+3]);
//FichierDescriptionMachine.remplir("1","2","3","4");
FichierDescriptionMachine.affiche();
FichierDescriptionMachine.enregistre("Fichier_description.xml");
}
static void supprimer(String s1,String s2,String s3,String s4)
{
for(int k=0;k<tab.length;k++)
if(tab[k]==s1 && tab[k+1]==s2 && tab[k+3]==s3 && tab[k+4]==s4)
for(int d=k;d<k+4;d++)
tab[d]=tab[d+4];
}
static void ajouter(String s1,String s2,String s3,String s4)
{int a=e,indice=0;
boolean var=true;
for(int g=0;g<tab.length;g=g+4)
{indice=indice+1;
if(tab[g]==s1)
{var=false;
break;}
}
if(var==true)
{
tab[a]=s1;
tab[a+1]=s2;
tab[a+2]=s3;
tab[a+3]=s4;
}
System.out.println(indice+"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
static void parcourFichier()
{
int j=0;
List listEtudiants = racine.getChildren("ordinateur");
Iterator i = listEtudiants.iterator();
while(i.hasNext())
{
Element courant = (Element)i.next();
// System.out.println(courant.getAttributeValue("classe"));
// System.out.println(courant.getChild("CPU").getText());
// System.out.println(courant.getChild("DRAM").getText());
// System.out.println(courant.getChild("IP").getText());
tab[j+0]=courant.getAttributeValue("classe");
tab[j+1]=courant.getChild("CPU").getText();
tab[j+2]=courant.getChild("DRAM").getText();
tab[j+3]=courant.getChild("IP").getText();
j=j+4;
e=j;
}
}
public static void afficherTab()
{
for(int k=0;k<tab.length;k++)
if(tab[k]!=null)
System.out.println(tab[k]);
}
} |
Partager