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
|
package test;
import nux.xom.io.*;
import nux.xom.xquery.*;
import nux.xom.*;
import nu.xom.*;
import nu.xom.Document;
import java.io.*;
import java.util.*;
//import org.jdom.*;
//import org.jdom.output.*;
public class TestApp {
public TestApp() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try{
File repertoire = new File("C:\\Users\\admin\\Documents\\NetBeansProjects\\test\\coll\\");
Document doctot=new Builder().build(new File ("C:\\Users\\admin\\Documents\\NetBeansProjects\\test\\tot.xml"));
int i=0;
OutputStream out=new FileOutputStream ("C:\\Users\\admin\\Documents\\NetBeansProjects\\test\\tot.xml");
Serializer ser=new Serializer(out);
Element ras = new Element("fichiers");
try{ ser.writeStartTag(ras);}catch (Exception e){System.out.println(e);}
for ( File file : repertoire.listFiles()) {
i=i+1;
// Traiter fichier
String p= file.getName();
String x="fichier";
Element racine = new Element(x);
racine.addAttribute(new Attribute("id", String.valueOf(i)));
doctot.fastInsertChild(racine, 1);
racine.appendChild(p);
}
ser.write(doctot);
out.close();
}catch(Exception e){System.out.println(e.getMessage());}
}
} |
Partager