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
| import org.w3c.dom.*;
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.io.BufferedReader;
import java.io.FileReader;
public class inventaire {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader("achats.txt"));
String line = null;
while ((line = br.readLine()) != null) {
String[] values = line.split(",");
for (String str : values) {
MettreAJourInventaire( achat[2], achat[3] );
Document doc = parser.parse("inventaire.xml");
Element racine = doc.getDocumentElement();
NodeList nl = racine.getChildNodes();
if (produit.getAttribute("code").equals(code)){
produit.setAttribute("quantité",Integer.toString(Integer.parseInt(produit.getAttribute("quantité")) - qte));
}
}
}
br.close();
}
}
TransformerFactory tfact = TransformerFactory.newInstance();
Transformer transformer = tfact.newTransformer();
transformer.setOutputProperty("encoding", "ISO-8859-1");
DOMSource source = new DOMSource(doc);
FileWriter fw = new FileWriter("inventaire.xml");
StreamResult result = new StreamResult(fw);
transformer.transform(source, result);
}
} |