Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1177070
  • 博文数量: 573
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 66
  • 用 户 组: 普通用户
  • 注册时间: 2016-06-28 16:21
文章分类

全部博文(573)

文章存档

2018年(3)

2016年(48)

2015年(522)

分类: C/C++

2015-12-02 20:16:21

编译命令

点击(此处)折叠或打开

  1. cc -I /home/eas/src/libxml/libxml2-2.6.30/include/ -I /home/eas/src/libiconv/libiconv-1.13.1/include/ -L/home/eas/src/libxml/libxml2-2.6.30/.libs -L/home/eas/src/libiconv/libiconv-1.13.1/lib/.libs/ -lxml2 -liconv -lz -lpthread -lm -o aptest aptest.c


点击(此处)折叠或打开

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <math.h>
  5. #include    <ctype.h>
  6. #include    <sys/stat.h>
  7. #include    <unistd.h>

  8. #include    <libxml/parser.h>                /* LIBXML2 Header File */
  9. #include    <libxml/tree.h>                    /* LIBXML2 Header File */
  10. #include     <libxml/xmlmemory.h>            /* LIBXML2 Header File */
  11. #include    <libxml/xpath.h>                /* LIBXML2 Header File */
  12. #include    <iconv.h>                        /* LIBXML2 Header File */

  13. #define FMLFLD_NOTARRAY 0 /* 非数组(用于下标参数) */
  14. #define FMLFLD_OPTIONAL 0 /* 可选域 */
  15. #define FMLFLD_REQUIRED 1 /* 必需域 */
  16. #define    SYM_FML_FS    0x40    /* 域分隔符0x1E*/
  17. #define    SYM_FML_NV    ':'     /* 名值分隔符*/
  18. #define    SYM_FML_AN    '#'     /* 数组下标起始符*/
  19. #define RC_SUCC 0
  20. #define RC_NFND -1
  21. #define RC_NSPC -2

  22. #define SZ_DATA_BUS (32*1024) /* 数据总线宽度 */
  23. typedef char T_DATABUS[SZ_DATA_BUS]; /* 数据总线 */

  24. void FmlDataClear(char *    cFmlData);
  25. char *FmlFieldSeek(const char *cFmlData, const char *cFieldName,int    iIndex);
  26. int    FmlFieldPut(char *cFmlData,int iBufSize,char *cFieldName,int iIndex,char *cFieldValue);
  27. int FmlFieldGet(const char *cFmlData,const char *cFieldName,int    iIndex,    char *cFieldValue,int iValueSize);
  28. int    FmlFieldNum(const char *cFmlData, const char *cFieldName, int *iNum);

  29. int CodeConvert(char* from_charset, char* to_charset, char* inbuf,size_t inlen, char* outbuf, size_t outlen);
  30. char* u2g(char *inbuf);
  31. char* g2u(char *inbuf);
  32. char * StrTrim(char * pstr);
  33. int JugeFileExist(char *lFileName);
  34. int APXmlParseFile(T_DATABUS tDataBus, char * pFilename, int * iMaxIndex);

  35. int main(int argc, char **argv)
  36. {
  37.     FILE *    fp = NULL;
  38.     int        iRet = -1;
  39.     int        iMaxIndex = -1;
  40.     char    filename[1024];
  41.     char    sParsefile[1024];
  42.     char    sXmlBuf[1024*1000*8];        /*从报文文件中读取的内容*/
  43.     char    sChildBuf[10240];        /*存放一次读取的文件内容*/
  44.     int        iXmlByteNum = 0;
  45.     
  46.     if(argc < 2)
  47.     {
  48.         printf("参数个数不对,应为2个!\n");
  49.         return -1;
  50.     }
  51.     
  52.     T_DATABUS tDataBus;
  53.     FmlDataClear(tDataBus);
  54.     memset(filename, 0x00, sizeof(filename));
  55.     memset(sParsefile, 0x00, sizeof(sParsefile));
  56.     memset(sXmlBuf, 0x00, sizeof(sXmlBuf));
  57.     memset(sChildBuf, 0x00, sizeof(sChildBuf));
  58.     
  59.     strcpy(filename, argv[1]);
  60.     StrTrim(filename);
  61.     sprintf(sParsefile, "%s%s%s", getenv("HOME"), "/src/xml_fun/", filename);
  62.     StrTrim(sParsefile);
  63.     
  64.     printf("***************************************************\n");
  65.     iRet = JugeFileExist(sParsefile);
  66.     if(iRet != RC_SUCC)
  67.     {
  68.         printf("文件[%s]不存在", sParsefile);
  69.         return -1;
  70.     }
  71.     
  72.     if((fp = fopen(sParsefile, "r")) == NULL)
  73.     {
  74.         printf("打开dmz文件[%s]失败", sParsefile);
  75.         return -1;
  76.     }
  77.     while(NULL != fgets(sChildBuf, sizeof(sChildBuf), fp))
  78.     {
  79.         strcat(sXmlBuf, sChildBuf);
  80.         memset(sChildBuf, 0, sizeof(sChildBuf));
  81.     }
  82.     iXmlByteNum = strlen(sXmlBuf);
  83.     printf("读取文件[%s],文件长度=[%d]", sParsefile, iXmlByteNum);    
  84.     printf("文件数据如下:\n[%s]", sXmlBuf);    
  85.     printf("***************************************************\n");
  86.     
  87.     APXmlParseFile(tDataBus, sParsefile, &iMaxIndex);
  88.     printf("总线=\n[%s]\n", tDataBus);
  89.     printf("***************************************************\n");
  90.     
  91.     return 0;
  92. }

  93. /*FmlDataClear 函数功能:清空数据总线函数*/
  94. void FmlDataClear(char *    cFmlData)
  95. {
  96.     cFmlData[0] = 0;
  97. }

  98. /*FmlFieldErase函数:擦除总线数据中的指定域,没有这个域就不擦除*/
  99. void    FmlFieldErase(char *cFmlData, const char *cFieldName,int iIndex)
  100. {
  101.     char    *p, *q;
  102.     if ( ( p = FmlFieldSeek( cFmlData, cFieldName, iIndex ) ) == NULL )
  103.         return; /*p指向指定的域名的起始地址*/
  104.     if ( ( q = strchr( p, SYM_FML_FS ) ) == NULL ) /*SYM_FML_FS:域分割符^^*/
  105.         q = p + strlen( p );
  106.     else
  107.         q ++; /*q指向域尾*/
  108.     strcpy( p, q ); /*p到q之间的被跳过*/
  109. }

  110. /*FmlFieldSeek函数功能:检索总线中指定域函数,返回指定域的起始地址*/
  111. char *FmlFieldSeek(const char *cFmlData, const char *cFieldName,int    iIndex)
  112. {
  113.     char    *p = (char *) cFmlData;
  114.     char    *n, *q, *v;
  115.     int    r;

  116.     while ( ( n = strchr( p, SYM_FML_FS ) ) != NULL )/*SYM_FML_FS:域分割符^^*/
  117.     {    
  118.         *n = 0; /*n指向下一个域分割符^^,并截断*/
  119.         q = strchr( p, SYM_FML_NV ); /*SYM_FML_NV:名值分割符:*/
  120.         *n = SYM_FML_FS; /*恢复域分割符,重新连上总线*/
  121.         if ( q != NULL )
  122.         {
  123.             *q = 0; /*q指向名值分割符:,并截断*/
  124.             if ( ( v = strchr( p, SYM_FML_AN ) ) != NULL ) /*0下标时,v=NULL*/
  125.                 *v = 0; /*v指向数组下标起始符#,并截断*/
  126.             if ( ( r = strcmp( p, cFieldName ) ) == 0 ) /*比较p指向的是不是待检索的域名*/
  127.             {
  128.                 if ( v == NULL && iIndex != FMLFLD_NOTARRAY || v != NULL && atoi( v + 1 ) != iIndex )
  129.                     r = -1; /*对下标值的检查,出错时r=-1*/
  130.             }
  131.             if ( v != NULL )
  132.                 *v = SYM_FML_AN; /*重新连上总线*/
  133.             *q = SYM_FML_NV; /*重新连上总线*/
  134.             if ( r == 0 ) /*域名匹配,下标也正确时,查找完毕*/
  135.                 return p; /*返回域名起始地址*/
  136.         }
  137.         p = n + 1; /*p指向下一个域名起始地址,继续循环查找*/
  138.     }
  139.     return NULL;
  140. }


  141. /*FmlFieldPut() 功能描述: 为总线中指定域赋值函数*/
  142. int    FmlFieldPut(char *cFmlData,int iBufSize,char *cFieldName,int iIndex,char *cFieldValue)
  143. {
  144.     int    s, l;
  145.     char    a[12];

  146.     FmlFieldErase( cFmlData, cFieldName, iIndex ); /*擦除指定域名域值*/

  147.     if ( iIndex == FMLFLD_NOTARRAY ) /*FMLFLD_NOTARRAY=0,判断是否是0下标*/
  148.         s = 0; /*0下标时,没有数组下标起始符#,也没有小标值0的显示*/
  149.     else
  150.         s = snprintf( a, sizeof( a ), "%d", iIndex ) + 1; /*下标的长度+#号码长度*/
  151.     if ( ( l = strlen( cFmlData ) ) + strlen( cFieldName ) + s + strlen( cFieldValue ) + 2 > iBufSize )
  152.         return RC_NSPC; /*判断是否溢出,其中2=域分隔符+'\0'*/
  153.     if ( l > 0 && cFmlData[l-1] != SYM_FML_FS ) /*SYM_FML_FS域分割符^^,原串没有域分割符时*/
  154.     {
  155.         cFmlData[l] = SYM_FML_FS; /*原串尾加上域分隔符*/
  156.         l ++; /*原串长+1*/
  157.     }

  158.     if ( s != 0 ) /*非0下标时*/
  159.         /*a中保存的是下标值*/
  160.         sprintf( cFmlData + l, "%s%c%s%c%s%c", cFieldName, SYM_FML_AN, a, SYM_FML_NV, cFieldValue, SYM_FML_FS );
  161.     else /*0下标时*/
  162.         sprintf( cFmlData + l, "%s%c%s%c", cFieldName, SYM_FML_NV,
  163.         cFieldValue, SYM_FML_FS );

  164.     return RC_SUCC;
  165. }


  166. /*FmlFieldGet() 功能描述: 从总线中取指定域值函数*/
  167. int FmlFieldGet(const char *cFmlData,const char *cFieldName,int    iIndex,    char *cFieldValue,int iValueSize)
  168. {
  169.     char    *p, *q, *v;
  170.     int    l;
  171.     
  172.     if ( ( p = FmlFieldSeek( cFmlData, cFieldName, iIndex ) ) == NULL )
  173.         return RC_NFND; /*p指向指定域名的起始地址*/
  174.     q = strchr( p, SYM_FML_NV ) + 1; /*SYM_FML_NV名值分隔符:,q指向域值的起始地址*/
  175.     if ( ( v = strchr( q, SYM_FML_FS ) ) == NULL ) /*SYM_FML_FS域分隔符^^,v指向域值的尾部地址*/
  176.         l = strlen( q ); /*没有串尾符^^的长度*/
  177.     else
  178.         l = v - q; /*l=域值的长度*/
  179.     if ( l >= iValueSize ) /*要放域值的空间不能小于域值的长度*/
  180.         return RC_NSPC;
  181.     memcpy( cFieldValue, q, l );
  182.     cFieldValue[l] = 0; /*域值的地址加字符串的结束符*/
  183.     return RC_SUCC;
  184. }


  185. /*FmlFieldNum() 功能描述: 统计总线中重复域的个数函数*/
  186. int    FmlFieldNum(const char *cFmlData, const char *cFieldName, int *iNum)
  187. {
  188.     char    *p = (char *) cFmlData;
  189.     char    *n, *q, *v;
  190.     int    r;
  191.     int    num,flag;

  192.     num=0;
  193.     flag=0;

  194.     while ( ( n = strchr( p, SYM_FML_FS ) ) != NULL )
  195.     {
  196.         *n = 0;
  197.         q = strchr( p, SYM_FML_NV );
  198.         *n = SYM_FML_FS;
  199.         if ( q != NULL )
  200.         {
  201.             *q = 0;
  202.             if ( ( v = strchr( p, SYM_FML_AN ) ) != NULL )
  203.                 *v = 0;
  204.             else
  205.             {
  206.                 *iNum=0;
  207.                 if( v != NULL)
  208.                     *v=SYM_FML_AN;
  209.                 *q=SYM_FML_NV;
  210.                 p = n + 1;
  211.                 continue;
  212.             }
  213.             if ( ( r = strcmp( p, cFieldName ) ) == 0 )
  214.             {
  215.                 num++;
  216.                 flag=1;
  217.             }
  218.                 *v=SYM_FML_AN;
  219.                 *q=SYM_FML_NV;
  220.         }
  221.         p = n + 1;
  222.     }
  223.     *iNum=num;
  224.     if(flag == 1)
  225.         return RC_SUCC;
  226.     else
  227.         return RC_NFND;
  228. }


  229. /*************************************************************
  230.  * 函 数 名:CodeConvert()
  231.  * 功能描述: 封装iconv相关函数
  232.  * 输入参数:from_charset - 转入字符码
  233.  *             to_charset - 转出字符妈
  234.  *             inbuf         - 转入字符
  235.  *             inlen         - 转入字符长度
  236.  *             outbuf     - 转出字符
  237.  *             outlen     - 转出字符长度
  238.  * 输出参数:outbuf     - 转出字符
  239.  *             outlen     - 转出字符长度
  240.  * 返 回:0 - 成功; -1 失败
  241.  * 说 明:
  242.  ************************************************************/
  243. int CodeConvert(char* from_charset, char* to_charset, char* inbuf,size_t inlen, char* outbuf, size_t outlen)
  244. {
  245.     iconv_t cd;
  246.     char** pin = &inbuf;
  247.     char** pout = &outbuf;
  248.     cd = iconv_open(to_charset,from_charset);
  249.     if(cd == (iconv_t)-1)
  250.         return -1;
  251.     memset(outbuf,0,outlen);
  252.     if(iconv(cd,(char**)pin,(size_t *)&inlen,(char**)pout,(size_t*)&outlen) == -1)
  253.         return -1;
  254.     iconv_close(cd);
  255.     return 0;
  256. }

  257. /*************************************************************
  258.  * 函 数 名:u2g()
  259.  * 功能描述: UTF-8码转成GBK码
  260.  * 输入参数:inbuf    - 转入字符
  261.  * 输出参数:
  262.  * 返 回:szOut - 成功; NULL - 失败
  263.  * 说 明:成功则返回一个动态分配的char*变量,需要在使用
  264.  *             完毕后手动free,失败返回NULL,使用有风险,调用需谨慎
  265.  char* u2g(char *inbuf)
  266. {
  267.     int nOutLen = 2 * strlen(inbuf) - 1;
  268.     char* szOut = (char*)malloc(nOutLen);
  269.     if (-1 == code_convert("utf-8","gb2312",inbuf,strlen(inbuf),szOut,nOutLen))
  270.     {
  271.        free(szOut);
  272.        szOut = NULL;
  273.     }
  274.     return szOut;
  275. }
  276.  ************************************************************/
  277. char* u2g(char *inbuf)
  278. {
  279.     size_t nOutLen = 0;
  280.     char* szOut = NULL;
  281.     if(!strlen(inbuf))
  282.         return NULL;
  283.     nOutLen = 2 * strlen(inbuf) - 1;
  284.     szOut = (char*)malloc(nOutLen);
  285.     if (-1 == CodeConvert("UTF-8","GBK",inbuf,strlen(inbuf),szOut,nOutLen))
  286.     {
  287.         free(szOut);
  288.         szOut = NULL;
  289.     }
  290.     return szOut;
  291. }

  292. /*************************************************************
  293.  * 函 数 名:g2u()
  294.  * 功能描述: GBK码转成UTF-8码
  295.  * 输入参数:inbuf    - 转入字符
  296.  * 输出参数:
  297.  * 返 回:szOut - 成功; NULL - 失败
  298.  * 说 明:成功则返回一个动态分配的char*变量,需要在使用
  299.  *             完毕后手动free,失败返回NULL,使用有风险,调用需谨慎
  300.  ************************************************************/
  301. char* g2u(char *inbuf)
  302. {
  303.     size_t nOutLen = 0;
  304.     char* szOut = NULL;
  305.     if(!strlen(inbuf))
  306.         return NULL;
  307.     nOutLen = 2 * strlen(inbuf) - 1;
  308.     szOut = (char*)malloc(nOutLen);
  309.     if (-1 == CodeConvert("GBK","UTF-8",inbuf,strlen(inbuf),szOut,nOutLen))
  310.     {
  311.         free(szOut);
  312.         szOut = NULL;
  313.     }
  314.     return szOut;
  315. }


  316. /*************************************************************
  317.  * 函 数 名:APXmlParseFile()
  318.  * 功能描述: 将xml文件解析成数据总线格式
  319.  * 输入参数:pFilename - 文件全路径
  320.  * 输出参数:tDataBus    - 数据总线
  321.  *          iMaxIndex    - 数据报文重复次数,总线最大下标值
  322.  * 返 回:0 - 成功 ;-1 - 失败
  323.  * 说 明:
  324.  ************************************************************/
  325. int APXmlParseFile(T_DATABUS tDataBus, char * pFilename, int * iMaxIndex)
  326. {
  327.     char *pFlag = NULL;
  328.     char *nodeName = NULL;
  329.     char *nodeValue = NULL;
  330.     char tempNodeValue[1024*10];
  331.     /* 定义解析文档指针 */
  332.     xmlDocPtr doc;
  333.     /* 定义结点指针 */
  334.     xmlNodePtr curNode, saveCurNode;
  335.     xmlChar* szAttr = NULL;
  336.     
  337.     
  338.     char*     name = NULL;
  339.     char     filename[1024];
  340.     memset(filename, 0, sizeof(filename));

  341.     int iRet = -1;
  342.     int i = -1;
  343.     int j = -1;

  344.     memset(tempNodeValue, 0, sizeof(tempNodeValue));
  345.     /* 解析文件"GB2312" */
  346.     printf("pFilename=[%s]\n", pFilename);
  347.     doc = xmlReadFile(pFilename, "GB2312", XML_PARSE_NOBLANKS);
  348.     if (NULL == doc)
  349.     {
  350.         printf("读取XML文件失败 文件名为[%s]\n",pFilename);
  351.         return -1;
  352.     }
  353.     //strcpy(filename, (char*)(doc->name));
  354.     printf("version=[%s]\n", (char*)(doc->version));
  355.     printf("encoding=[%s]\n", (char*)(doc->encoding));
  356.     printf("URL=[%s]\n", (char*)doc->URL);
  357.     printf("name=[%s]\n", (char*)(doc->name));
  358.     printf("_private=[%s]\n", (char*)(doc->_private));
  359.     //name=u2g((char*)doc->name);_private
  360.     //printf("name=[%s]\n", name);
  361.     
  362.     /* 确定文档根元素 */
  363.     curNode = xmlDocGetRootElement(doc);
  364.     /*检查确认当前文档中包含内容*/
  365.     if (NULL == curNode)
  366.     {
  367.         printf("empty document\n");
  368.         xmlFreeDoc(doc);
  369.         return -1;
  370.     }
  371.     if( xmlStrcmp(curNode->name,BAD_CAST "ap") )
  372.     {
  373.         printf("xml文件中ap属性未找到!\n");
  374.         xmlFreeDoc(doc);
  375.         return -1;
  376.     }

  377.     curNode = curNode->children; /*指向body节点或者head节点*/
  378.     do
  379.     {
  380.         /*记录这个2级节点的指针*/
  381.         saveCurNode = curNode;
  382.         if( (xmlStrcmp(curNode->name,BAD_CAST "body"))&&(xmlStrcmp(curNode->name,BAD_CAST "head")) )
  383.         {
  384.             printf("second node !=body或者head\n");
  385.             xmlFreeDoc(doc);
  386.             return -1;
  387.         }
  388.         curNode = curNode->children; /*指向3级节点*/
  389.         do
  390.         {
  391.             
  392.             char * tempnodeName;
  393.             tempnodeName = u2g((char*)curNode->name);
  394.             printf("******************************************\n");
  395.             printf("curNode->name=[%s]\n", curNode->name);
  396.             xmlNodePtr tempcurNode;
  397.             tempcurNode = curNode->parent; //指向该节点的父节点
  398.             
  399.             xmlChar* tempszAttr = xmlNodeGetContent(tempcurNode);
  400.             tempnodeName = u2g((char*)tempcurNode->name);
  401.             printf("tempcurNode->name=[%s]\n", tempcurNode->name);
  402.             printf("******************************************\n");
  403.             
  404.     
  405.             szAttr = xmlNodeGetContent(curNode);
  406.             nodeName = u2g((char*)curNode->name);
  407.             nodeValue = u2g((char*)szAttr);
  408.             for(i=0; ; i++)
  409.             {
  410.                 memset(tempNodeValue, 0, sizeof(tempNodeValue));
  411.                 iRet = FmlFieldGet(tDataBus, nodeName, i, tempNodeValue, sizeof(tempNodeValue));
  412.                 if(iRet < 0)
  413.                 {
  414.                     /*节点名nodeName,所对应的下标i,不存在*/
  415.                     if(nodeValue != NULL)
  416.                     {
  417.                         /*当是批量转账交易,请求报文多记录数据字段RespPrvData时,有特殊处理,需要跳过前13个'|'*/
  418.                         if(strncmp(nodeName, "RespPrvData", strlen("RespPrvData")) == 0)
  419.                         {
  420.                             if((pFlag = strchr(nodeValue, '|')) == NULL)
  421.                             {
  422.                                 printf("RespPrvData字段报文格式错\n");
  423.                                 return -1;
  424.                             }
  425.                             for(j=0; j<12; j++)
  426.                             {
  427.                                 pFlag = pFlag + 1;
  428.                                 if((pFlag = strchr(pFlag, '|')) == NULL)
  429.                                 {
  430.                                     printf("RespPrvData字段报文格式错\n");
  431.                                     return -1;
  432.                                 }
  433.                             }
  434.                             pFlag = pFlag + 1;
  435.                             iRet = FmlFieldPut(tDataBus, SZ_DATA_BUS, nodeName, i, pFlag);
  436.                             if(iRet < 0)
  437.                             {
  438.                                 printf("FmlFieldPut失败, iRet=[%d]\n", iRet);
  439.                                 return -1;
  440.                             }
  441.                         }
  442.                         /*当是批量换汇交易,请求报文多记录数据字段exchange_data时,有特殊处理,需要跳过前19个'|'*/
  443.                         else if(strncmp(nodeName, "exchange_data", strlen("exchange_data")) == 0)
  444.                         {
  445.                             if((pFlag = strchr(nodeValue, '|')) == NULL)
  446.                             {
  447.                                 printf("exchange_data字段报文格式错\n");
  448.                                 return -1;
  449.                             }
  450.                             for(j=0; j<18; j++)
  451.                             {
  452.                                 pFlag = pFlag + 1;
  453.                                 if((pFlag = strchr(pFlag, '|')) == NULL)
  454.                                 {
  455.                                     printf("exchange_data字段报文格式错\n");
  456.                                     return -1;
  457.                                 }
  458.                             }
  459.                             pFlag = pFlag + 1;
  460.                             iRet = FmlFieldPut(tDataBus, SZ_DATA_BUS, nodeName, i, pFlag);
  461.                             if(iRet < 0)
  462.                             {
  463.                                 printf("FmlFieldPut失败, iRet=[%d]\n", iRet);
  464.                                 return -1;
  465.                             }
  466.                         }
  467.                         else
  468.                         {
  469.                             iRet = FmlFieldPut(tDataBus, SZ_DATA_BUS, nodeName, i, nodeValue);
  470.                             if(iRet < 0)
  471.                             {
  472.                                 printf("FmlFieldPut失败, iRet=[%d]\n", iRet);
  473.                                 return -1;
  474.                             }
  475.                         }
  476.                     }
  477.                     else
  478.                     {
  479.                         iRet = FmlFieldPut(tDataBus, SZ_DATA_BUS, nodeName, i, "");
  480.                         if(iRet < 0)
  481.                         {
  482.                             printf("FmlFieldPut失败, iRet=[%d]\n", iRet);
  483.                             return -1;
  484.                         }
  485.                     }
  486.                     xmlFree(szAttr);
  487.                     if( nodeName != NULL );
  488.                     {
  489.                         free(nodeName);
  490.                         nodeName = NULL;
  491.                     }
  492.                     if( nodeValue != NULL );
  493.                     {
  494.                         free(nodeValue);
  495.                         nodeValue = NULL;
  496.                     }
  497.                     if(i > *iMaxIndex) /*记录最大下标值*/
  498.                     {
  499.                         *iMaxIndex = i;
  500.                     }
  501.                     break; /*即可跳出本次循环*/
  502.                 }
  503.                 else
  504.                 {
  505.                     /*节点名nodeName,所对应的下标i,存在*/
  506.                     continue;
  507.                 }
  508.             }
  509.         }
  510.         while((curNode = curNode->next) != NULL);
  511.     }
  512.     while((curNode = saveCurNode->next) != NULL);

  513.     xmlFreeDoc(doc);
  514.     return 0;
  515. }

  516. char * StrTrim(char * pstr)
  517. {
  518.     if(NULL == pstr)
  519.     {
  520.         return NULL;
  521.     }
  522.     char * phead = pstr;
  523.     char * ptail = pstr + strlen(pstr) - 1;
  524.     while((*phead == ' ')&&(phead < ptail)) phead++;
  525.     while((*ptail == ' ')&&(ptail > phead)) ptail--;
  526.     *(ptail + 1) = '\0';
  527.     memcpy(pstr, phead, sizeof(char)*(ptail - phead + 2));
  528.     return pstr;
  529. }

  530. /***********************************************************
  531.  * 函 数 JugeFileExist()
  532.  * 功能描述: 判断文件是否存在
  533.  * 输入参数: lFilename 长文件名
  534.  * 返 回: 0 文件存在
  535.  * 1 文件不存在
  536.  * 流程描述:
  537.  * 说明:
  538.  * 修改记录:
  539.  * [修改人] [日期][描述]
  540. ***********************************************************/
  541. int JugeFileExist(char *lFileName)
  542. {
  543.     struct stat statbuf;
  544.     memset(&statbuf,0,sizeof(statbuf));
  545.     stat(lFileName,&statbuf);
  546.     if(statbuf.st_mode & S_IFREG)
  547.         return 0;
  548.     else
  549.         return 1;
  550. }
解析的文件

点击(此处)折叠或打开

  1. <ap>
  2.     <head>
  3.         <tr_code>910101</tr_code>
  4.         <corp_no>7340507440001</corp_no>
  5.         <user_no>BECK</user_no>
  6.         <serial_no></serial_no>
  7.         <req_no>141</req_no>
  8.         <tr_acdt>20130517</tr_acdt>
  9.         <tr_time>140816</tr_time>
  10.         <atom_tr_count>1</atom_tr_count>
  11.         <channel>1</channel>
  12.         <sign>123</sign>
  13.         <filename></filename>
  14.         <ogl_serial_no></ogl_serial_no>
  15.         <reserved></reserved>
  16.     </head>
  17.     <body>
  18.         <RespPrvData>cert_no|pay_acno|pay_acname|pay_bank_no|Amt|rcv_acno|rcv_acname|rcv_bank_no|cur_code|Postscript|MemNo|fund_use|remark|100000069557|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069558|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069559|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069560|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069561|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069562|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069563|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069564|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069565|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069566|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069567|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069568|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069569|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069570|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069571|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069572|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069573|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069574|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069575|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|100000069576|31001559100056018898|上海期货交易所|52368|10.00|31001559100056010003|上海良茂期货经纪有限公司|52368|01||0003|批准划转款|8888,综合帐户,0003,代理账户|</RespPrvData>
  19.         <field_num>13</field_num>
  20.         <record_num>20</record_num>
  21.     </body>
  22. </ap>

阅读(677) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~