lnk commit front code
This commit is contained in:
145
include/xmltools.h
Normal file
145
include/xmltools.h
Normal file
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* @file xmltools.h
|
||||
* @brief <20><><EFBFBD>ݿ<EFBFBD>XML<4D>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
|
||||
*
|
||||
* @version $Revision: 1.1 $
|
||||
* @date $Date: 2018/11/24 06:54:50 $
|
||||
* @author $Author: lizhongming $
|
||||
* @state $State: Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _XMLTOOLS_H
|
||||
#define _XMLTOOLS_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utf.h"
|
||||
|
||||
typedef int (*db_parser_handler)(char* buf,void* object,void* rdb);
|
||||
typedef int (dbparser_fn_t)(char* buf,void* object,void* rdb);
|
||||
|
||||
|
||||
/** Skip unused part of xml
|
||||
* set skip tag and the levels,
|
||||
* when the end tag handler encounters the same depth , the
|
||||
* skipped element has ended and the flag be cleared!
|
||||
* assuming {root}=1 ,skip flag and skip depth
|
||||
*/
|
||||
typedef struct xml_parse_skip_t xml_parse_skip_t;
|
||||
struct xml_parse_skip_t{
|
||||
int skip_flag; /**< is skip */
|
||||
int skip_depth; /**< which level of the depth */
|
||||
int global_depth;/**< {root}=1 */
|
||||
};
|
||||
|
||||
#define XML_TOOLS_ATTR_AND (1) //attr is and relation
|
||||
#define XML_TOOLS_ATTR_OR (2) //attr is or-relation
|
||||
|
||||
#define XMLTOOLS_MAX_PATH_LEN (10) //<2F><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define XMLTOOLS_MAX_VALUE_LEN (64) //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ﳤ<EFBFBD><EFB3A4>
|
||||
#define XMLTOOLS_MAX_TAG_LEN (32) //<2F><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>
|
||||
#define XMLTOOLS_MAX_NAME XMLTOOLS_MAX_TAG_LEN
|
||||
#define XMLTOOLS_MAX_ATTR_LEN (3) //max 3 attrs
|
||||
|
||||
typedef char** elem_text ;
|
||||
typedef struct path_session_t path_session_t;
|
||||
typedef struct attr_pair attr_pair;
|
||||
|
||||
struct attr_pair{
|
||||
char name[XMLTOOLS_MAX_NAME];
|
||||
char value[XMLTOOLS_MAX_TAG_LEN];
|
||||
};
|
||||
typedef enum type_identifier_e type_identifier_e;
|
||||
enum type_identifier_e{
|
||||
axis_child,
|
||||
axis_attribute,
|
||||
predicate
|
||||
};
|
||||
/** contains one seesion of xpath*/
|
||||
struct path_session_t
|
||||
{
|
||||
type_identifier_e type_identifier;
|
||||
char tag[XMLTOOLS_MAX_TAG_LEN]; /**< */
|
||||
attr_pair attrs[XMLTOOLS_MAX_ATTR_LEN]; /**< ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϵ */
|
||||
//attr_pair * current;//current position of attr_pair ,used internal
|
||||
int level; /**< desired level, root elem is 1*/
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief ͨ<><CDA8>һ<EFBFBD>α<EFBFBD><CEB1><EFBFBD>XML<4D>ļ<EFBFBD><C4BC><EFBFBD>ȡijһ<C4B3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
* @param filename XML<4D>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
* @param path element·<74><C2B7>
|
||||
* @param item element<6E><74><EFBFBD><EFBFBD>
|
||||
* @param output_data <20><><EFBFBD><EFBFBD>element<6E><74><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return <20><><EFBFBD><EFBFBD> APR_SUCCESS - <20>ɹ<EFBFBD>
|
||||
* APR_NOTFOUND - element<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* APR_EBADF - <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
APR_DECLARE(int) xml_db_attach(const char* filename,const char* path,
|
||||
const char* item, db_parser_handler pfn,void* output_data);
|
||||
|
||||
/**
|
||||
* @brief <20><>ȡXML<4D>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD>element<6E><74><EFBFBD><EFBFBD>ֵ
|
||||
* @param filename XML<4D>ļ<EFBFBD><C4BC><EFBFBD>
|
||||
* @param path elementȫ·<C8AB><C2B7>
|
||||
* @param value <20><>ȡ<EFBFBD><C8A1>element<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
* @return <20><><EFBFBD><EFBFBD> APR_SUCCESS - <20>ɹ<EFBFBD>
|
||||
* APR_NOTFOUND - element<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* APR_EBADF - <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @note
|
||||
<pre>Example:
|
||||
char *value = NULL;
|
||||
rv= xml_get_elem("SYSCONF.xml","//systemconf/IPBCASTB/", &value);
|
||||
//Example:
|
||||
//<systemconf>
|
||||
// <VERSION type="386">1.0</VERSION>
|
||||
// <IPBCASTB > 172.20.255.255 </IPBCASTB>
|
||||
//</systemconf>
|
||||
//
|
||||
//<2F><><EFBFBD><EFBFBD>XPATH<54>
|
||||
//axis-identifier::node-test[predicate1][predicate2]..
|
||||
|
||||
//rv=xml_get_elem("SYSCONF.xml","//systemconf/IPBCASTB/", &value);
|
||||
|
||||
value=" 172.20.255.255 "
|
||||
|
||||
//rv=xml_get_elem("SYSCONF.xml","//systemconf/VERSION/@type/", &value);
|
||||
|
||||
value="386"
|
||||
//rv=xml_get_elem("SYSCONF.xml","//systemconf/VERSION[attribute::type="386"]/", &value);
|
||||
|
||||
value="1.0"
|
||||
//ע<><D7A2>Ŀǰν<C7B0><CEBD>ֻ֧<D6BB><D6A7>=<3D>ţ<EFBFBD>ֻ֧<D6BB><D6A7>attribute<74><65>,ֻ֧<D6BB><D6A7>1<EFBFBD><31>ν<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ʽ<EFBFBD><CABD>
|
||||
</pre>
|
||||
*/
|
||||
APR_DECLARE(int) xml_get_elem(const char* filename,const char* path, char **value);
|
||||
|
||||
/**
|
||||
* @brief dbparser_fn_retrieve
|
||||
* @param fn_name Ҫȡ<D2AA>õ<EFBFBD><C3B5><EFBFBD>ע<EFBFBD>ắ<EFBFBD><E1BAAF><EFBFBD><EFBFBD>
|
||||
*/
|
||||
APR_DECLARE(dbparser_fn_t*) dbparser_fn_retrieve(const char *fn_name);
|
||||
|
||||
/**
|
||||
* @brief dbparser_fn_register
|
||||
* @param fn_name Ҫע<D2AA>ắ<EFBFBD><E1BAAF><EFBFBD><EFBFBD>
|
||||
* @param pfn <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
APR_DECLARE(void) dbparser_fn_register(const char *fn_name,dbparser_fn_t *pfn, apr_pool_t *pool);
|
||||
|
||||
|
||||
APR_DECLARE(int) xml_get_elem_free_memory(void *point);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _XMLTOOLS_H */
|
||||
Reference in New Issue
Block a user