package gis;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.*;
public class pro {
String[] data=new String[60000];
int s,datanumber;
int[] p1=new int[300];
int[] p2=new int[300];
String[] geo=new String[60000];
String[] code=new String[60000];
String[] name=new String[60000];
String[] town=new String[60000];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
readx("data.xml");
int sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("<gml:posList>")>-1)sx=sx+1;
if(data[s].indexOf("<gml:posList>")>-1)p1[sx]=s;
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("</gml:posList>")>-1)sx=sx+1;
if(data[s].indexOf("</gml:posList>")>-1)p2[sx]=s;
}
int number=sx;
for(s=1;s<number+1;s++){
sx=p1[s]+1;
String str=data[sx];
for(sx=p1[s]+2;sx<p2[s];sx++){
str=str+"△"+data[sx];
}
str=str.replace(" ","");
str=str.replace(" ","〇");
geo[s]=str;
}
System.out.println("b=>"+sx);
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("AdministrativeAreaCode.xml")>-1)sx=sx+1;
if(data[s].indexOf("AdministrativeAreaCode.xml")>-1)code[sx]=rev(data[s]);
}
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("CityName")>-1)sx=sx+1;
if(data[s].indexOf("CityName")>-1)name[sx]=rev(data[s]);
}
System.out.println(sx);
sx=0;
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("<ksj:Location>")>-1)sx=sx+1;
if(data[s].indexOf("<ksj:Location>")>-1)town[sx]=rev(data[s]);
}
System.out.println(sx);
for(s=1;s<number+1;s++){
data[s]=name[s]+","+code[s]+","+town[s]+","+geo[s];
}
datanumber=number;
writexml("data.txt");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<datanumber+1;s++){
pw.println(data[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String rev(String str){
int p1=str.indexOf(">");
int p2=str.indexOf("<",p1);
String strx=str.substring(p1+1,p2);
return strx;
}
void readx(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2017年03月22日 20:13