Il codice che mi realizza l'xml sopra è questo:
codice:
import java.io.*;
import java.util.*;
//IMPORTIAMO I PACKAGE NECESSARI PER LAVORATE CON GLI XML
import org.jdom.*;
import org.jdom.output.XMLOutputter;
public class CreaXML
{
public static String PATH="C:\\Programmi\\Apache Group\\Tomcat 4.1\\webapps\\rosi\\xml\\";
public CreaXML(String nomeFile)
{
try
{
writeFile(this.PATH+nomeFile);
}
catch(Exception e)
{
System.err.println ("errore: "+e);
}
}
public void writeFile(String path) throws Exception
{
File fileTmp = new File(path);
//ISTANZIAMO UN OGGETTO Element PASSANDOGLI LA STRINGA CHE SARA' IL NOME DEL NOSTRO SUPERTAG
Element root = new Element("root");
//ISTANZIAMO UN OGGETTO Document PASSANDOGLI COME PARAMETRO L'OGGETTO ELEMENT PRECEDENTEMENTE ISTANZIATO
Document documento = new Document(root);
//AGGIUNGIAMO AL NOSTRO ELEMENT UN ATTRIBUTO: <root attributo=valore>
root = root.setAttribute( "attributo","valore");
//ISTANZIAMO ALTRI OGGETTI Element PASSANDOGLI LE STRINGHE CHE SARANNO I NOMI DEI NOSTRI TAG
Element initparam = new Element("init-param");
Element paramname = new Element("param-name");
Element paramvalue = new Element("param-value");
//ASSEGNAMO DEI VALORI AI TAG param-name E param-value:<param-name>mio nome</param-name>
paramname.addContent("mio nome");
paramvalue.addContent("mio valore");
//AGGIUNGIAMO I TAG param-name E Param-value AL TAG init-param
initparam.addContent(paramname);
initparam.addContent(paramvalue);
//AGGIUNGIAMO IL TAG init-param AL SUPERTAG root
root.addContent(initparam);
BufferedWriter out = null;
try
{
out = new BufferedWriter(new FileWriter(path));
//ISTANZIAMO LA CLASSE XMLOutputter CHE CI PERMETTE DI FORMATTARE IL FILE XML.
XMLOutputter xout = new XMLOutputter();
xout.setIndent(true);
xout.setNewlines(true);
//CON QUESTA ISTRUZIONE SCRIVIAMO IL DOCUMENTO documento IN UN BufferedWriter CHE CREA IL FILE TRAMITE UN FileWriter
xout.output(documento,out);
}
catch (IOException e)
{
System.err.println ("errore: "+e);
}
finally
{
try
{
out.close();
}
catch(IOException e)
{
System.err.println ("errore: "+e);
}
}
}
public static void main(String args[])
{
CreaXML crea = new CreaXML(args[0]);
}
}
qualcuno dove e cosa devo aggiungere per ottenere anche
<?xml-stylesheet type="text/xsl" href="miofile.xsl"?>