Ciao ragazzi.....ho un file che ha una struttura xml ma non contiene la radice
codice:
<Alert>
<Name>DIMET</Name>
<Time>12.29.02</Time>
<Level>High</Level>
<TagID>200110901</TagID>
<Message>PRESENTE</Message>
</Alert><Alert>
<Name>DIMET</Name>
<Time>12.29.02</Time>
<Level>High</Level>
<TagID>200110902</TagID>
<Message>PRESENTE</Message>
</Alert>
Questo file viene aggiornato e sovrascritto ogni 2 secondi.Dovrei fare un parser tramite jdom per poi inserire i dati all'interno di un database,quindi ho creato una funzione in netbeans che mi permette di copiare il contenuto di questo file di origine all'interno di un file di destinazione,con l'aggiunta della radice.Questo è il codice
codice:
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import java.io.FileOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintStream;
import java.io.*;
import java.util.*;


public class esempio1 {
public static void main(String[] args) throws IOException{
FileWriter fw = new FileWriter("c:/filedidestinazione.txt");
PrintWriter out = new PrintWriter(fw);
OutputStreamWriter fout = new OutputStreamWriter(new FileOutputStream("c:/filedidestinazione.txt",true)); //true per fare l'append e non sovrascrivere
PrintWriter out1 = new PrintWriter(fout);
out.println("<root>");
out1.print("</root>");
try{
BufferedReader i = new BufferedReader(new InputStreamReader(new FileInputStream("c:/filediorigine.txt"),UTF-8));
String str = i.readLine();
while(str!=null){
out.println(str);
str=i.readLine();}
}
catch(UnsupportedEncodingException ue){
System.out.println("Not supported : ");
}
out.close();
out1.close();
out1.flush();
}
}
ma il risultato del file di destinazione è il seguente.....
codice:
<root>
< A l e r t > 

< N a m e > D I M E T < / N a m e > 

< T i m e > 1 2 . 2 9 . 0 2 < / T i m e > 

< L e v e l > H i g h < / L e v e l > 

< T a g I D > 2 0 0 1 1 0 9 0 1 < / T a g I D > 

< M e s s a g e > P R E S E N T E < / M e s s a g e > 

< / A l e r t > < A l e r t > 

< N a m e > D I M E T < / N a m e > 

< T i m e > 1 2 . 2 9 . 0 2 < / T i m e > 

< L e v e l > H i g h < / L e v e l > 

< T a g I D > 2 0 0 1 1 0 9 0 2 < / T a g I D > 

< M e s s a g e > P R E S E N T E < / M e s s a g e > 

< / A l e r t >
e quindi il parser viene arrestato perchè il file non è strutturato bene.
Mi sapreste dire dove sbaglio??Grazie in anticipo-
Daniele.