//si el firxer de sortida es XML executarem aquesta funcio per crear el archiu XML corresponent
//aquesta bariable agafa tot el fitxer del xml
String XML="";
//aquesta agafa tot el fitxer xml per afegir un tros de codi
String XMLPle="";
//senyalem l'entrada i la sortida
File sortida=new File("C:\\DAM2\\PROJECTE_1\\Fitxers_sortida\\Fitxer_sortida.xsd");
File entrada2=new File("C:\\DAM2\\PROJECTE_1\\Fitxers_sortida\\Fitxer_sortida.xml");
FileReader frx = new FileReader(entrada2);
BufferedReader brx = new BufferedReader(frx);
//executem la funcio que genera el XML
xml(dadesGenerades,nombreRegistresGenerar);
//aquest bucle agafa tot el fitxer XML i el posa en un string
while(brx.ready()) {
XML = XML+ brx.readLine();
}
//separem el artxiu xml per ">"
String[] Xml=XML.split(">");
//fem aquest bucle per implementar la linea de codi que li falta
for(i=0;i<Xml.length;i++) {
if (i==1) {
XMLPle=XMLPle+Xml[i]+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"file:///C:/DAM2/PROJECTE_1/Fitxers_sortida/Fitxer_sortida.xsd\">";
}
else {
XMLPle=XMLPle+Xml[i];
}
}
//reescribim el fitxer XML
try (FileWriter escriptor1 =new FileWriter(sortida);) {
escriptor1.append(XMLPle).write('\n');
} catch (IOException e) {
System.err.println(e.getMessage());
}
//executem la funcio per generar el XSD i passem el XSD a un String
String text=xsd(liniesNoms);
//Creem el artxiu XSD amb el String fet anteriorment
try (FileWriter escriptor2 =new FileWriter(sortida);) {
escriptor2.append(text).write('\n');
} catch (IOException e) {
System.err.println(e.getMessage());
}
Actualitzaccio del if de la sortida XML