Created
August 25, 2013 13:47
-
-
Save brokendish/6333924 to your computer and use it in GitHub Desktop.
xml_CSV_Get.c 作成中ーまだ動かない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include "xml_CSV_Getlib.h" | |
/* デバグ用定義 */ | |
/*#define DEBUG1*/ | |
/* | |
---------------------------------------------------------------------- | |
気象庁のMXLファイルから必要な部分を抽出してCSVファイルにする | |
「xml_CSV_Getlib.c」の「xmlCSV_Get_Main」実行用のドライバ | |
---------------------------------------------------------------------- | |
名前 | |
xml_CSV - XMLデータ(電文、ファイル)の内容をリスト表示する | |
(xmlCSV_Get_Main実行用のドライバ) | |
書式 | |
./xml_CSV [int opt] [char *xml] | |
[int opt] 0:メモリーから読込 1:ファイルから読込 2:標準入力から読込(パイプで入力) | |
[char *xml] (opt=0):XML文字列(電文) (opt=1):XMLファイルのフルパス (opt=2):標準入力から取得 | |
説明 | |
【コンパイル方法】 | |
gcc -o xml_CSV xml_CSV_Get.c xml_CSV_Getlib.c -lxml2 | |
【デバグ用コンパイル(DEBUG1)】 | |
gcc -D DEBUG1 -o xml_CSV xml_CSV_Get.c xml_CSV_Getlib.c -lxml2 | |
【メモリー読込用の実行 (opt=0)】 | |
./xml_CSV 0 `cat tokusyu-3.xml` | |
【標準入力読込用の実行 (opt=2)】 | |
cat tokusyu-3.xml|./xml_CSV 2 | |
【コンパイル&実行】 | |
gcc -o xml_CSV xml_CSV_Get.c xml_CSV_Getlib.c -lxml2 && cat tokusyu-3.xml|./xml_CSV 2 | |
---------------------------------------------------------------------- | |
*/ | |
/* | |
---------------------------------------------------------------------- | |
関数定義 | |
---------------------------------------------------------------------- | |
"xml_CSV_Get.h" | |
*/ | |
/* | |
---------------------------------------------------------------------- | |
メイン処理 | |
XMLパースに必要な情報「XML名前空間」「XML Xpath」を設定し配列に格納し、 | |
「xmlCSV_Get_Main」を呼び出してXML処理を行う | |
---------------------------------------------------------------------- | |
*/ | |
int main(int argc, char **argv) | |
{ | |
char *input_file; | |
int opt; | |
/* | |
if (argc != 2) { | |
printf("引数が足りない!!か、多いかも!\n"); | |
return 1; | |
} | |
*/ | |
/* | |
----設定ファイル読込処理----------------------------------------------------------------S | |
*/ | |
/* char *configfile = "xml_CSV.conf"; | |
FILE *fpp; | |
int ret=9; | |
*/ | |
/* 設定ファイルのオープン処理 */ | |
/* if((fpp = fopen(configfile,"r"))==NULL){ | |
printf("設定ファイル「%s」が開けません。\n",configfile); | |
} | |
*/ | |
/* 1文字ずつ読み込み */ | |
/* int c; | |
while( (c = getc( fpp )) != EOF ){ | |
printf( "%c", c ); | |
} | |
int c; | |
while( (c = fgetc( fpp )) != EOF ){ | |
printf( "%c", c ); | |
} | |
*/ | |
/* 1行ずつ読み込み | |
char s[100]; | |
while(fscanf(fpp,"%s",s) != EOF){ | |
printf( "%s\n", s ); | |
} | |
*/ | |
/* char s[255]; | |
char *xstr_nsp[255]; | |
char *xstr_xpt[255]; | |
char bufstr[255]; | |
int cnt_nsp=0; | |
int cnt_xpt=0; | |
*/ | |
/* 1行ずつ読み込み */ | |
/*while( fgets( s, 255, fpp ) != NULL ){*/ | |
/* while(fscanf(fpp,"%s",s) != EOF){ | |
printf( "%s\n", s ); | |
*/ | |
/* 正規表現による検索を実行する */ | |
/* ret = regex_seek(s, "<*namespase>|<*xpath>");*/ | |
/* 一致しない場合配列に格納 */ | |
/* if(ret == 1){ | |
if(strlen(s)>1){ | |
if(strcmp("<namespase>",bufstr)==0){ | |
xstr_nsp[cnt_nsp]=malloc(sizeof(char [255])); | |
strcpy(xstr_nsp[cnt_nsp],s); | |
printf("xstr_nsp[cnt_nsp]---%d:%s\n",cnt_nsp,xstr_nsp[cnt_nsp]); | |
cnt_nsp++; | |
} | |
if(strcmp("<xpath>",bufstr)==0){ | |
xstr_xpt[cnt_xpt]=malloc(sizeof(char [255])); | |
strcpy(xstr_xpt[cnt_xpt],s); | |
printf("xstr_xpt[cnt_xpt]---%d:%s\n",cnt_xpt,xstr_xpt[cnt_xpt]); | |
cnt_xpt++; | |
} | |
} | |
} | |
else{ | |
printf("ELSE----%s\n",s); | |
strcpy(bufstr,s); | |
} | |
} | |
fclose(fpp); | |
int oo=0; | |
for(oo=0;xstr_nsp[oo] != NULL;oo++){ | |
printf("xstr_nsp@@-----%d:%s\n",oo,xstr_nsp[oo]); | |
} | |
int count; | |
for(count=0;xstr_xpt[count]!=NULL;count++){} | |
count--; | |
printf("count %d",count); | |
int oj=0; | |
for(oj=0;xstr_xpt[oj] != NULL;oj++){ | |
printf("xstr_xpt@@-----%d%s\n",oj,xstr_xpt[oj]); | |
} | |
*/ | |
/* | |
----設定ファイル読込処理----------------------------------------------------------------E | |
*/ | |
opt = atoi(argv[1]); | |
input_file = argv[2]; | |
/* ダミーデータ(とりあえず作成) xmlns属性(XML名前空間(ネームスペース))用 | |
*/ | |
char *xstr_nsp[3]; | |
xstr_nsp[0]= "x,http://xml.kishou.go.jp/jmaxml1/"; | |
xstr_nsp[1]= "xh,http://xml.kishou.go.jp/jmaxml1/informationBasis1/"; | |
xstr_nsp[2]= "xb,http://xml.kishou.go.jp/jmaxml1/body/meteorology1/"; | |
#ifdef DEBUG1 | |
printf("-NSP-------配列数-----\n"); | |
int aa = test(xstr_nsp); | |
#endif | |
/* ダミーデータ(とりあえず作成) XML Xpath用 | |
*/ | |
char *xstr_xpt[5]; | |
xstr_xpt[0]= "/x:Report/x:Control/x:Status"; | |
xstr_xpt[1]= "/x:Report/xh:Head/xh:TargetDateTime"; | |
xstr_xpt[2]= "/x:Report/xb:Body/xb:MeteorologicalInfos/xb:MeteorologicalInfo/xb:Item/xb:Station/xb:Name"; | |
xstr_xpt[3]= "/x:Report/xb:Body/xb:MeteorologicalInfos/xb:MeteorologicalInfo/xb:Item/xb:Station/xb:Location"; | |
xstr_xpt[4]= "/x:Report/xb:Body/xb:AdditionalInfo/xb:ObservationAddition/xb:Text"; | |
#ifdef DEBUG1 | |
printf("-XPATH-------配列数-----\n"); | |
int aaa = test(xstr_xpt); | |
#endif | |
/* xmlCSV_Get_Main実行 */ | |
xmlCSV_Get_Main(opt,input_file,xstr_xpt,xstr_nsp); | |
/* | |
free(xstr_xpt); | |
free(xstr_nsp); | |
*/ | |
} | |
/*--------------------------------------------------------------------------------------------------------*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment