Foros del Web » Programación para mayores de 30 ;) » Programación General »

Problemas para generar XML

Estas en el tema de Problemas para generar XML en el foro de Programación General en Foros del Web. Hola estoy tratando de generar un XML a partir de un archivo cvs en base aun manual que me encotre en la RED, estoy tratando ...
  #1 (permalink)  
Antiguo 11/01/2011, 13:05
 
Fecha de Ingreso: octubre-2007
Mensajes: 2
Antigüedad: 16 años, 6 meses
Puntos: 0
Mensaje Problemas para generar XML

Hola estoy tratando de generar un XML a partir de un archivo cvs en base aun manual que me encotre en la RED, estoy tratando de ejcutar una Clase que viene en el manual pero al ejecutarla me marca erro y no lo puedo lograr el archivo csv contiene solamente una linea

"418","National Endowment for the Humanities","00","National Endowment for the Humanities","0200","National Endowment for the Humanities: grants and administration","59","503","Research and general education aids","Discretionary","On-budget", 0, 0, 0, 121275, 145231, 150100, 151299, 130560, 135447, 140118, 139478, 132582, 138890, 140435, 153000, 156910, 170002, 175955, 177413, 177491, 172000, 110000, 110000, 111000, 112000, 115000, 120000, 121000, 124000, 126000, 129000, 132000

y la clase que esta ejecutandose es la siguiente



import java.io.*;
import java.util.*;


public class FlatXMLBudget {

public static void convert(List data, OutputStream out)
throws IOException {

Writer wout = new OutputStreamWriter(out, "UTF8");
wout.write("<?xml version=\"1.0\"?>\r\n");
wout.write("<Budget>\r\n");

Iterator records = data.iterator();
while (records.hasNext()) {
wout.write(" <LineItem>\r\n");
Map record = (Map) records.next();
Set fields = record.entrySet();
Iterator entries = fields.iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
String name = (String) entry.getKey();
String value = (String) entry.getValue();
// some of the values contain ampersands and less than
// signs that must be escaped
value = escapeText(value);

wout.write(" <" + name + ">");
wout.write(value);
wout.write("</" + name + ">\r\n");
}
wout.write(" </LineItem>\r\n");
}
wout.write("</Budget>\r\n");
wout.flush();

}

public static String escapeText(String s) {

if (s.indexOf('&') != -1 || s.indexOf('<') != -1
|| s.indexOf('>') != -1) {
StringBuffer result = new StringBuffer(s.length() + 4);
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '&') result.append("&amp;");
else if (c == '<') result.append("&lt;");
else if (c == '>') result.append("&gt;");
else result.append(c);
}
return result.toString();
}
else {
return s;
}

}

public static void main(String[] args) {

try {

if (args.length < 1) {
System.out.println("Usage: FlatXMLBudget infile outfile");
return;
}

InputStream in = new FileInputStream(args[0]);
OutputStream out;
if (args.length < 2) {
out = System.out;
}
else {
out = new FileOutputStream(args[1]);
}

List results = BudgetData.parse(in);
convert(results, out);
}
catch (IOException e) {
System.err.println(e);
}

}

}


pero me marca varios erroes cuando la compilo
javac -Xlint BudgetData.java

Tengo que compilarla con el -Xlint para que me de el detalle de errores

la veradad soy nuevo en esto del mundo java alguien pudiera orientarme sobre esto?

Etiquetas: xml
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:45.