package xml;
import tool.*;
import java.io.*;
public class pro {
String[] data=new String[5000];
String[] cr=new String[5000];
int s,datanumber;
String file;
String str;
int creditnumber;
String[][] credit=new String[50000][2];
String[] year=new String[5000];
String[] month=new String[5000];
String[][] v=new String[500][100];
public static void main(String[] args) {
pro res=new pro();
}
pro(){
file="data.csv";
readfile sub=new readfile();
sub.makedata(file,"UTF-8");
data=sub.data;
datanumber=sub.datanumber;
str=data[4];
String[] x1=str.split(",");
for(s=1;s<x1.length;s++){
if(x1[s]==null)x1[s]="";
if(x1[s].length()<1)x1[s]=x1[s-1];
}
str=data[5];
String[] x2=str.split(",");
str=data[6];
String[] x3=str.split(",");
for(s=0;s<x3.length;s++){
str=x1[s]+x2[s]+x3[s];
str=str.replace("\n","");
cr[s]=str.replace(" ","");
}
creditnumber=1;
for(s=5;s<115;s++){
String[] y=data[s].split(",");
year[s]=y[1];
month[s]=y[2];
}
int sx;
for(s=10;s<115;s++){
str=change(data[s]);
String[] z=str.split(",");
for(sx=3;sx<15;sx++){
v[s][sx]=z[sx];
}
}
writexml("ren.xml");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println("<?xml version='1.0' encoding='UTF-8'?>");
for(s=10;s<115;s++){
for(sx=3;sx<15;sx++){
pw.print("<data>");
pw.print("<year>");
pw.print(year[s]);
pw.print("</year>");
pw.print("<month>");
pw.print(month[s]);
pw.print("</month>");
pw.print("<credit>");
pw.print(cr[sx]);
pw.print("</credit>");
pw.print("<value>");
pw.print(v[s][sx]);
pw.print("</value>");
pw.println("</data>");
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String change(String str){
int p1,sx,s;
int[] c1=new int[500];
int cnumber;
p1=str.indexOf("\"");
sx=0;
if(p1>-1)sx=sx+1;
if(p1>-1)c1[sx]=p1;
while(p1>-1){
p1=str.indexOf("\"",p1+1);
if(p1>-1)sx=sx+1;
if(p1>-1)c1[sx]=p1;
}
cnumber=sx;
String strx,str2;
int s1,h;
str2=str.substring(0,c1[1]);
for(s=1;s<cnumber;s++){
strx=str.substring(c1[s]+1,c1[s+1]);
s1=s/2;
s1=2*s1;
h=0;
if(s1==s)h=100;
if(h<50)str2=str2+strx.replace(",", "");
if(h>50)str2=str2+strx;
}
return str2;
}
}
最終更新:2014年02月26日 03:35