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
|
public static void main(String[] args) throws Exception
{
// TODO Auto-generated method stub
StringBuffer ch=new StringBuffer("coucou");
SAXBuilder sxb = new SAXBuilder();
System.out.println(ch);
//"CommentsTest.xml"
//FileChannel in = new FileInputStream("CommentsTest.xml").getChannel();
//int size = (int) in.size();
//bytes = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
//char c = (char) bytes.get();
//ByteBuffer bytes = ByteBuffer.allocateDirect(1024);
//FileChannel in = new FileInputStream("fichier").getChannel();
//int read = in.read(bytes);
//char c = (char) bytes.get();
XMLReader xr = XMLReaderFactory.createXMLReader();
MySAXApp handler = new MySAXApp("Concept","fileName");
xr.setContentHandler(handler);
xr.setErrorHandler(handler);
// Parse each file provided on the
// command line. chemin absolu obligatoire
FileReader r = new FileReader("ICBC_UAT_P1_090714a.xml");
xr.parse(new InputSource(r));
//On crée un nouveau document JDOM avec en argument le fichier XML
//Le parsing est terminé ;)
String nomFichier;
int cpt;
DecimalFormat df = new DecimalFormat("000");
cpt = handler.getCpt();
//contruction du nom du fichier de récup
for (int i = 1; i < cpt+1 ; i++){
nomFichier = ("fileName")+ df.format(i);
try
{
//System.out.println(nomFichier);
document = sxb.build(new File(nomFichier) +(".xml"));
//création du fichier
//_myFile = new FileWriter(("fileName")+ df.format(i) +(".txt"));
//création du buffer en RAM du fichier
//_tampon = new BufferedWriter(_myFile);
}
catch(Exception e){}
//On initialise un nouvel élément racine avec l'élément racine du document.
racine = document.getRootElement();
//Méthode définie dans la partie 3.2. de cet article
createFile(nomFichier);
}
}
private static void createFile(String nomFichier) {
//On crée une List contenant tous les noeuds "FinancialConcept" de l'Element racine
List <Element> listConcept = (List <Element>)racine.getChildren("FinancialConcept");
//On crée un Iterator sur notre liste
Iterator <Element> E = listConcept.iterator();
try{
//création du fichier
_myFile = new FileWriter("f:/recup1.xls");
//création du buffer en RAM du fichier
_tampon = new BufferedWriter(_myFile);
} |
Partager